Opened 13 years ago

Closed 13 years ago

#15960 closed New feature (fixed)

Allow SimpleListerFilter's lookups to be based on the available data

Reported by: Julien Phalip Owned by: nobody
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Shortly after SimpleListFilter landed in [16144], there were talks on IRC with jezdez, carljm and apollo13 about allowing filter lookups to be based on the available data. Taking the DecadeBornListFilter example from the doc (http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter), you might want to only display the lookups for the decades where people were actually born in. This requires the lookups() method to have access to the ModelAdmin's queryset, somehow.

I'm attaching a patch with a suggested implementation.

Attachments (2)

15960.simplelistfilter-queryset-based-lookups.diff (12.8 KB ) - added by Julien Phalip 13 years ago.
15960.simplelistfilter-queryset-based-lookups.2.diff (12.8 KB ) - added by Julien Phalip 13 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Carl Meyer, 13 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

This looks pretty reasonable and useful to me, as far as the API addition goes. Couple minor typos in the docs portion of the patch: "ModelAdmin objects" where it should be "ModelAdmin object", and one case of books_90s that should be born_in_90s.

comment:2 by Julien Phalip, 13 years ago

Oops, bad copy and paste. I've fixed those typo ;)

comment:3 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16152]:

Fixed #15960 -- Extended list filer API added in r16144 slightly to pass the current model admin to the SimpleListFilter.lookups method to support finer grained control over what is filtered over. Many thanks to Carl Meyer and Julien Phalip for the suggestion and patch.

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