Allow icontains lookup to accept uuids with or without dashes
We have Django 2.1 project with model admin which includes an UUIDField in list_display and search_fields. The UUID is displayed with dashes on changelist (e.g. "245ba2eb-6852-47be-82be-7dc07327cf9e") and if the user cut'n'paste it to the search field, I would expect admin to find it.
This works however only on Postgres but fails on Oracle. I can understand why this happens (Oracle backend stores uuid as string) and I believe I can workaround it by customizing get_search_results but I think should be internal thing that Django handles gracefully - search should be possible by the value as displayed in admin.
Change History
(12)
| Component: |
contrib.admin → Database layer (models, ORM)
|
| Summary: |
Admin search for UUID with dashes works only on Postgres → Allow icontains lookup to accept uuids with or without dashes
|
| Triage Stage: |
Unreviewed → Accepted
|
| Type: |
Bug → Cleanup/optimization
|
| Owner: |
changed from nobody to Ian Foote
|
| Status: |
new → assigned
|
| Patch needs improvement: |
set
|
| Version: |
2.1 → master
|
| Patch needs improvement: |
unset
|
| Triage Stage: |
Accepted → Ready for checkin
|
| Resolution: |
→ fixed
|
| Status: |
assigned → closed
|
This isn't really an admin issue but rather it's due to the fact that the default admin lookup uses
__icontains. You could fix the issue by usingsearch_fields = ['uuidfield__exact'](adding__exact) although that doesn't allow searching for part of the UUID value.I'll tentatively accept the ticket to allow
QuerySet.objects.filter(uuidfield__icontains='...')to work with values with or without dashes