Opened 14 years ago

Closed 11 years ago

Last modified 11 years ago

#15961 closed New feature (fixed)

Admin search should be pluggable

Reported by: Jeremy Dunck Owned by: anonymous
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: kmike84@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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)

comment:1 by Aymeric Augustin, 14 years ago

Triage Stage: UnreviewedDesign decision needed

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.

comment:2 by Jeremy Dunck, 14 years ago

For some additional context, I've seen search_fields queries take hours to complete, where an equivalent Solr search would be seconds.

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

#17669 was a duplicate.

comment:5 by Mikhail Korobov, 13 years ago

Cc: kmike84@… added

comment:7 by kunitoki@…, 12 years ago

Related ticket with initial code example > #17669

comment:8 by Aymeric Augustin, 12 years ago

Triage Stage: Design decision neededAccepted

The idea doesn't seem controversial, bumping to "accepted".

comment:9 by Philippe Ombredanne, 12 years ago

+1

comment:10 by anonymous, 11 years ago

Owner: changed from nobody to anonymous
Status: newassigned

comment:11 by Bozidar Benko <bbenko@…>, 11 years ago

Owner: anonymous removed
Status: assignednew

comment:12 by Bozidar Benko <bbenko@…>, 11 years ago

Owner: set to anonymous
Status: newassigned

comment:13 by Bozidar Benko <bbenko@…>, 11 years ago

comment:14 by Russell Keith-Magee, 11 years ago

Patch needs improvement: set

Documentation needs review - there's a few typos; but the code looks good to me.

comment:15 by Russell Keith-Magee, 11 years ago

One other comment - add yourself to the AUTHORS file.

comment:16 by Bozidar Benko <bbenko@…>, 11 years ago

Fixed documention with Daniele's help.

comment:17 by Bozidar Benko <bbenko@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 2d309a7043e3625cfeeadbc252322e5599dfffc0:

Fixed #15961 -- Modified ModelAdmin to allow for custom search methods.

This adds a get_search_results method that users can override to
provide custom search strategies.

Thanks to Daniele Procida for help with the docs.

comment:18 by Russell Keith-Magee <russell@…>, 11 years ago

In c0719d076f36ad908d0ab77e36f7f60a771e3c80:

Merge pull request #1166 from bbenko/ticket_15961

Fixed #15961 -- Added get_search_results to ModelAdmin

comment:19 by Loic Bistuer <loic.bistuer@…>, 11 years ago

In 470a9bb22d4471744e5c20af5d755b232312d58c:

Moved get_search_results from BaseModelAdmin to ModelAdmin.

Refs #15961.

comment:20 by Tim Graham <timograham@…>, 11 years ago

In 9053c6da5fcfe98c05527591f9fd785223eb354a:

[1.6.x] Moved get_search_results from BaseModelAdmin to ModelAdmin.

Refs #15961.

Backport of 470a9bb22d from master.

comment:21 by Tim Graham <timograham@…>, 11 years ago

In 90bdb42702327a4ef74e74d2e123da0731a90c4c:

[1.6.x] Fixed backport error in previous commit; refs #15961

Note: See TracTickets for help on using tickets.
Back to Top