Opened 3 years ago

Closed 3 years ago

#15960 closed New feature (fixed)

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

Reported by: julien 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:


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 (, 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 3 years ago.
15960.simplelistfilter-queryset-based-lookups.2.diff (12.8 KB) - added by julien 3 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 3 years ago by carljm

  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 3 years ago by julien

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

comment:3 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.