Admin search should be pluggable
RIght now, the ModelAdmin search_fields functionality is implemented in admin.views.ChangeList.get_query_set:
http://code.djangoproject.com/browser/django/tags/releases/1.3/django/contrib/admin/views/main.py#L256
Choosing search fields often requires tough tradeoffs between utility (searching all fields that are likely useful) and performance (joining over large M2M traversals is hard on the DB).
It would be good if the implementation for search_fields were pluggable; on the current project, I wish I could use Haystack/Solr there.
What about adding a hook, .get_search_results(self, query) which would return either a queryset or a list of primary keys? The rest of ChangeList could remain unchanged, just incorporating the result into the QuerySet resulting from get_query_set.
As for declaring a backend, how about adding ModelAdmin.search_backend which is a dotted python-path string?
Change History
(21)
Triage Stage: |
Unreviewed → Design decision needed
|
Triage Stage: |
Design decision needed → Accepted
|
Owner: |
changed from nobody to anonymous
|
Status: |
new → assigned
|
Owner: |
anonymous removed
|
Status: |
assigned → new
|
Owner: |
set to anonymous
|
Status: |
new → assigned
|
Patch needs improvement: |
set
|
Resolution: |
→ fixed
|
Status: |
assigned → closed
|
This is a rather important feature, and there are many questions in the initial report. I think its design should be discussed on the mailing list.