Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use computed property for autocomplete search #36

Open
brylie opened this issue Feb 6, 2019 · 5 comments
Open

Use computed property for autocomplete search #36

brylie opened this issue Feb 6, 2019 · 5 comments

Comments

@brylie
Copy link
Contributor

brylie commented Feb 6, 2019

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?

@harrislapiroff
Copy link
Collaborator

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?

@brylie
Copy link
Contributor Author

brylie commented Feb 25, 2019

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 :-)

@harrislapiroff
Copy link
Collaborator

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. 🤔

@harrislapiroff
Copy link
Collaborator

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.

@harrislapiroff harrislapiroff changed the title Use computed property for autocomplete_search_field? Use computed property for autocomplete search May 17, 2019
@ababic
Copy link

ababic commented Nov 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants