wagtail-autocomplete
wagtail-autocomplete copied to clipboard
Use computed property for autocomplete search
Is it possible to use a model property for the autocomplete_search_field
? E.g. a property like full_name
that concatenates two fields first_name
and last_name
?
Unfortunately, because autocomplete_search_field
is concatenated directly into a database query, computing it using python isn't possible. I'm open to considering implementations of this (maybe we can create a autocomplete_search(search: str) -> Queryset
method that defaults to our current implementation but is overridable...
@brylie Can you tell me more about your use case?
Well, we basically needed to search for authors for an article. The authors table had given_name
and family_name
, fields, with a full_name
property. I ended up adding a database field full_name
and populating the value in the save
hook. This feature request was early in my troubleshooting :-)
That makes sense—and that's also the sort of thing that could plausibly be solved in-database with annotations or something like them. Hmmmmmmm. 🤔
I'm officially marking this as a desirable feature and will accept a PR that makes the autocomplete search method customizable. See discussion in #47 for more information.
Hi guys. It seems to me that flexibility could be greatly improved by allowing a list of fields to be specified for searching rather than limiting it to a single field. You could put the query together like so (note: the query string can also be split to allow single-word matching on different fields):
https://github.com/wagtail/wagtail/blob/master/wagtail/contrib/modeladmin/helpers/search.py#L31