Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#15961 closed New feature (fixed)

Admin search should be pluggable

Reported by: jdunck 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 Changed 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Design 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 Changed 4 years ago by jdunck

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

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

#17669 was a duplicate.

comment:5 Changed 3 years ago by kmike

  • Cc kmike84@… added

comment:7 Changed 3 years ago by kunitoki@…

Related ticket with initial code example > #17669

comment:8 Changed 2 years ago by aaugustin

  • Triage Stage changed from Design decision needed to Accepted

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

comment:9 Changed 2 years ago by pombredanne

+1

comment:10 Changed 2 years ago by anonymous

  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

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

  • Owner anonymous deleted
  • Status changed from assigned to new

comment:12 Changed 2 years ago by Bozidar Benko <bbenko@…>

  • Owner set to anonymous
  • Status changed from new to assigned

comment:13 Changed 2 years ago by Bozidar Benko <bbenko@…>

comment:14 Changed 2 years ago by russellm

  • Patch needs improvement set

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

comment:15 Changed 2 years ago by russellm

One other comment - add yourself to the AUTHORS file.

comment:16 Changed 2 years ago by Bozidar Benko <bbenko@…>

Fixed documention with Daniele's help.

comment:17 Changed 2 years ago by Bozidar Benko <bbenko@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

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 Changed 2 years ago by Russell Keith-Magee <russell@…>

In c0719d076f36ad908d0ab77e36f7f60a771e3c80:

Merge pull request #1166 from bbenko/ticket_15961

Fixed #15961 -- Added get_search_results to ModelAdmin

comment:19 Changed 2 years ago by Loic Bistuer <loic.bistuer@…>

In 470a9bb22d4471744e5c20af5d755b232312d58c:

Moved get_search_results from BaseModelAdmin to ModelAdmin.

Refs #15961.

comment:20 Changed 2 years ago by Tim Graham <timograham@…>

In 9053c6da5fcfe98c05527591f9fd785223eb354a:

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

Refs #15961.

Backport of 470a9bb22d from master.

comment:21 Changed 2 years ago by Tim Graham <timograham@…>

In 90bdb42702327a4ef74e74d2e123da0731a90c4c:

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

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