Opened 22 months ago
Closed 9 months ago
#34339 closed New feature (wontfix)
Allow overriding construct_search().
Reported by: | Ramez Issac | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 4.1 |
Severity: | Normal | Keywords: | admin search |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In ModelAdmin, get_search_result
uses an inner function construct_search
to add the icontains , istartswith, iexact
It can be much easier for more customization, if construct_search function was override-able.
FYI, My Case is: i can not add a related id field to search_fields... have to use traversing .
class MyAdmin(admin.ModelAdmin): search_fields = ['client_id', # wont work 'client__id' # will work ]
Change History (4)
comment:1 by , 22 months ago
Easy pickings: | unset |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Summary: | Enhancement: easier search field customization → Allow overriding construct_search(). |
Type: | Uncategorized → New feature |
comment:2 by , 9 months ago
I would need to use search unaccent sensitive in the admin search.
Ideally, I would be able to override construct_search as :
def custom_construct_search(field_name): if field_name.startswith("^"): return "%s__unaccent__istartswith" % field_name[1:] elif field_name.startswith("="): return "%s__unaccent__iexact" % field_name[1:] elif field_name.startswith("@"): return "%s__unaccent__search" % field_name[1:] else: return "%s__unaccent__icontains" % field_name
How else would you recommend doing so ?
comment:3 by , 9 months ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
comment:4 by , 9 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Hello averta, please do not reopen tickets closed as wontfix
without following the proper process (see details).
If you need help understanding how Django works or how you can achieve something specifically, please see TicketClosingReasons/UseSupportChannels for ways to get help.
In such cases, you can always use the
__exact
lookup, e.g.There is no need to change
construct_search()
.