#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.4b7c0dc15a3ca44aa1ea25c2156a7d4e%40djangoproject.com.