Opened 18 years ago

Last modified 16 years ago

#3096 closed defect

Filtering choices in admin list view don't respond to limit_choices_to parameter — at Initial Version

Reported by: Archatas (aidas.bendoraitis at gmail.com) Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: normal Keywords: nfa-someday yandex-sprint ep2008
Cc: myer0052@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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()

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top