#3096: Filtering choices in admin list view don't respond to limit_choices_to
parameter
---------------------------------------------------------+------------------
   Reporter:  Archatas (aidas.bendoraitis at gmail.com)  |                
Owner:  nobody         
     Status:  new                                        |            
Component:  Admin interface
    Version:  newforms-admin                             |           
Resolution:                 
   Keywords:                                             |                
Stage:  Accepted       
  Has_patch:  1                                          |           
Needs_docs:  0              
Needs_tests:  0                                          |   
Needs_better_patch:  1              
---------------------------------------------------------+------------------
Old description:

> Administration list view shows choices in filters not responding to the
> limit_choices_to field for the field.
>
> For example, if we have
>
> class Color(models.Model):
>     value=models.CharField(...)
>     warm=models.BooleanField(...)
>
> class Thing(models.Model):
>     title=models.CharField(...)
>     color=models.ForeignKey(Color, limit_choices_to={'warm': True})
>     class Admin:
>         list_filter = ('color',)
>
> We will get all the choices of Color objects listed in the Filter/By
> Color section instead of getting only those, which are warm.
>
> To fix this, the line
> {{{
> self.lookup_choices = f.rel.to._default_manager.all()
> }}}
> at class RelatedFilterSpec(FilterSpec) in the file
> django/contrib/admin/filterspecs.py has to be changed to
> {{{
> if f.rel.limit_choices_to:
>     self.lookup_choices =
> f.rel.to._default_manager.filter(**f.rel.limit_choices_to)
> else:
>     self.lookup_choices = f.rel.to._default_manager.all()
> }}}

New description:

 Administration list view shows choices in filters not responding to the
 limit_choices_to field for the field.

 For example, if we have

 {{{
 #!python
 class Color(models.Model):
     value=models.CharField(...)
     warm=models.BooleanField(...)

 class Thing(models.Model):
     title=models.CharField(...)
     color=models.ForeignKey(Color, limit_choices_to={'warm': True})
     class Admin:
         list_filter = ('color',)
 }}}

 We will get all the choices of Color objects listed in the Filter/By Color
 section instead of getting only those, which are warm.

 To fix this, the line
 {{{
 #!python
 self.lookup_choices = f.rel.to._default_manager.all()
 }}}
 at class RelatedFilterSpec(FilterSpec) in the file
 django/contrib/admin/filterspecs.py has to be changed to
 {{{
 #!python
 if f.rel.limit_choices_to:
     self.lookup_choices =
 f.rel.to._default_manager.filter(**f.rel.limit_choices_to)
 else:
     self.lookup_choices = f.rel.to._default_manager.all()
 }}}

Comment (by gwilson):

 formatted ticket description

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3096#comment:10>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to