[Answered ]-How to search by related model field using django-extra-views?

1👍

Newer versions of django have a security feature which prevents lookups on related models.
The workaround can be found on this question:
Django: Filtering by %filter% not allowed

👤Renoc

1👍

You cannot specify which of the fields will be searched in the query parameter of the URL. Your URL should look like this:

http://{VIEW_URL}?q=ADAM

This will search in both contact__first_name and contact__last_name fields, since those are the fields specified by the *search_field* attribute of your view.

You can have a look at the get_queryset method of the SearchableListMixin class to see how the query is parsed and of the class handles both the query parameter and the search fields.

👤JSTL

Leave a comment