Opened 4 years ago

Closed 4 years ago

#31587 closed New feature (wontfix)

List filters are selected only for queries with explicit __exact lookups.

Reported by: Anael Mobilia Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

As described on the documentation, there is implicit use of

xxx__id__exact

Equivalents are :

xxx_id    # __exact is implied
xxx_pk   # __pk implies __id__exact

Example app is in attachment.
I generated a link on the contrib.admin (Country admin view) in order to be able to list all people living in a country.
All the following links provides the same correct result (only people living on the country are displayed) :

        url = '<a href="{baseurl}?country__id__exact={country}">Show inhabitants</a>'
        url = '<a href="{baseurl}?country__id={country}">Show inhabitants</a>'
        url = '<a href="{baseurl}?country__pk={country}">Show inhabitants</a>'

On the destination admin view (People), I have set a list_filter on Country.

Only the first link select the currently filtered Country on the filter list (on the right of the screen on the People admin view), the two others links doesn't.

As the last two selectors are shortcuts for the fully explicit form, I suggest to have the same render on the filter list (current value is selected/highlighted).

Tested on Django 3.0.6.

Regards

Attachments (2)

example.tar.xz (3.0 KB ) - added by Anael Mobilia 4 years ago.
Example app
correct_result.png (4.2 KB ) - added by Anael Mobilia 4 years ago.
Render of the correct result on the list filter

Download all attachments as: .zip

Change History (3)

by Anael Mobilia, 4 years ago

Attachment: example.tar.xz added

Example app

by Anael Mobilia, 4 years ago

Attachment: correct_result.png added

Render of the correct result on the list filter

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: wontfix
Status: newclosed
Summary: Django admin - list_filter visually selected for query using implicit xx__id__exactList filters are selected only for queries with explicit __exact lookups.
Type: UncategorizedNew feature
Version: 3.0master

Thanks for this ticket, however that's how the admin is implemented. We use explicit lookups also in other filters. I don't see much value in supporting other lookup shortcuts in each filter. You can always subclass RelatedFieldListFilter if you really need this.

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