[Django] #26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields

37 views
Skip to first unread message

Django

unread,
Dec 29, 2015, 8:45:17 AM12/29/15
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
------------------------------------------------+------------------------
Reporter: timgraham | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Currently,
[https://github.com/django/django/pull/5883#issuecomment-167767767 all
queries are done as string lookups] which gives something like this on
PostgreSQL, for example:
`("admin_views_pluggablesearchperson"."age"::text) = UPPER(20))`. It would
be more efficient if the admin cast the search value to an integer and
used that for the query.

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

Django

unread,
Feb 27, 2016, 7:32:37 PM2/27/16
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: timgraham | Owner: akki
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

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

* owner: nobody => akki
* status: new => assigned


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

Django

unread,
Feb 28, 2016, 9:47:22 AM2/28/16
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: timgraham | Owner: akki
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by akki):

* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/6219

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:2>

Django

unread,
Feb 28, 2016, 10:45:56 AM2/28/16
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: timgraham | Owner: akki
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by charettes):

I think we should favor the approach suggested in #26184 instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:3>

Django

unread,
Mar 4, 2016, 6:50:39 PM3/4/16
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: timgraham | Owner: akki
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

I agree, let's revisit this if it doesn't.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:4>

Django

unread,
Jun 30, 2016, 12:31:10 AM6/30/16
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: timgraham | Owner:

Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by akki):

* owner: akki =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:5>

Django

unread,
Jul 5, 2017, 6:21:40 AM7/5/17
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Krzysztof
Type: | Nazarewski
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Krzysztof Nazarewski):

* owner: (none) => Krzysztof Nazarewski


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:6>

Django

unread,
Jul 5, 2017, 6:58:27 AM7/5/17
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)

Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Krzysztof Nazarewski):

* owner: Krzysztof Nazarewski => (none)


* status: assigned => new


Comment:

Related to #26184

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:7>

Django

unread,
Jul 20, 2018, 4:12:09 PM7/20/18
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

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

* needs_better_patch: 1 => 0
* has_patch: 1 => 0


Comment:

As far as I tested, you can now use something like `search_fields =
['votes__exact']` to do the appropriate query, however, if a non-integer
search term is entered, the page crashes with `ValueError invalid literal
for int() with base 10: 'abc'` from `IntegerField.get_prep_value()`.
Probably that exception should be caught in
`ModelAdmin.get_search_results()` and no results returned.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:5>

Django

unread,
Aug 26, 2018, 11:15:00 PM8/26/18
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Nick
Type: | Sandford
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

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

* owner: nobody => Nick Sandford


* status: new => assigned


Comment:

PR: [https://github.com/django/django/pull/10339]

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:6>

Django

unread,
Aug 26, 2018, 11:15:15 PM8/26/18
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Nick
Type: | Sandford
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Sandford):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:7>

Django

unread,
Sep 14, 2018, 2:21:50 PM9/14/18
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Nick
Type: | Sandford
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:8>

Django

unread,
Jun 30, 2020, 7:25:57 AM6/30/20
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields do an integer lookup for IntegerFields
-------------------------------------+-------------------------------------
Reporter: Tim Graham | Owner: Nick
Type: | Sandford
Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Niclas Olofsson):

Replying to [comment:5 Tim Graham]:


> As far as I tested, you can now use something like `search_fields =
['votes__exact']` to do the appropriate query, however, if a non-integer
search term is entered, the page crashes with `ValueError invalid literal
for int() with base 10: 'abc'` from `IntegerField.get_prep_value()`.
Probably that exception should be caught in
`ModelAdmin.get_search_results()` and no results returned.

We have to consider that there might be multiple search fields of mixed
types though, i.e. `search_fields = ['votes__exact', 'title',
'text__contains']`, just so the matches for other fields does not get
discarded just because one of the fields threw an error.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:9>

Django

unread,
Nov 30, 2022, 5:05:52 AM11/30/22
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Nick Sandford => (none)


* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:10>

Django

unread,
Nov 30, 2022, 5:06:38 AM11/30/22
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

#34191 was a duplicate for `DecimalField`.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:11>

Django

unread,
Dec 23, 2022, 6:37:48 PM12/23/22
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by mishachernyshov):

Replying to [comment:11 Mariusz Felisiak]:


> #34191 was a duplicate for `DecimalField`.

You can use __iexact instead of __exact for non-string fields, I think, it
even makes sense, because the word `exact` means complete equality even
with type. It works for me.

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:12>

Django

unread,
Jan 28, 2024, 9:50:08 AMJan 28
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Sandeep Pal):

can i work on this?
--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:13>

Django

unread,
Feb 7, 2024, 12:32:33 PMFeb 7
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: Saurabh
Type: Cleanup/optimization | Status: assigned

Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Saurabh ):

* owner: (none) => Saurabh


* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:14>

Django

unread,
Feb 20, 2024, 5:21:35 AMFeb 20
to django-...@googlegroups.com
#26001: Make ModelAdmin.search_fields raise data errors on __exact lookups for non-
string fields.
--------------------------------------+------------------------------------
Reporter: Tim Graham | Owner: Saurabh
Type: Cleanup/optimization | Status: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Saurabh ):

PR: https://github.com/django/django/pull/17885
--
Ticket URL: <https://code.djangoproject.com/ticket/26001#comment:15>
Reply all
Reply to author
Forward
0 new messages