[Django] #31587: Django admin - list_filter visually selected for query using implicit xx__id__exact

4 views
Skip to first unread message

Django

unread,
May 14, 2020, 11:36:01 AM5/14/20
to django-...@googlegroups.com
#31587: Django admin - list_filter visually selected for query using implicit
xx__id__exact
-----------------------------------------+------------------------
Reporter: Anael Mobilia | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Hello,

As [https://docs.djangoproject.com/en/3.0/topics/db/queries/#the-pk-
lookup-shortcut 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

--
Ticket URL: <https://code.djangoproject.com/ticket/31587>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 14, 2020, 11:36:28 AM5/14/20
to django-...@googlegroups.com
#31587: Django admin - list_filter visually selected for query using implicit
xx__id__exact
-------------------------------+--------------------------------------

Reporter: Anael Mobilia | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Anael Mobilia):

* Attachment "example.tar.xz" added.

Example app

Django

unread,
May 14, 2020, 11:36:50 AM5/14/20
to django-...@googlegroups.com
#31587: Django admin - list_filter visually selected for query using implicit
xx__id__exact
-------------------------------+--------------------------------------

Reporter: Anael Mobilia | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Anael Mobilia):

* Attachment "correct_result.png" added.

Render of the correct result on the list filter

Django

unread,
May 15, 2020, 1:05:32 AM5/15/20
to django-...@googlegroups.com
#31587: List filters are selected only for queries with explicit __exact lookups.
-------------------------------+--------------------------------------

Reporter: Anael Mobilia | Owner: nobody
Type: New feature | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed
* type: Uncategorized => New feature
* version: 3.0 => master
* resolution: => wontfix


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/31587#comment:1>

Reply all
Reply to author
Forward
0 new messages