Exact search for fields in Django admin

I am trying to set up Django admin bindings for a specific model so that I can quickly filter the exact value of a specific field. I know I can manually manipulate the GET parameters for this:

?fieldname__exact=foobar

      

What I cannot do is get the sidebar to display a small form where I can enter this value. I know what I can add fieldname

to list_filter

, but this doesn't scale far beyond tens of unique values. I did some research on django-advanced-filters, but it doesn't seem to be compatible with Django 1.11.

How can I implement an exact search for a specific field in Django admin?

+3


source to share


1 answer


a little late but i hope this still helps someone

possible configurations for the search box are listed at http://www.django-rest-framework.org/api-guide/filtering/#searchfilter .

'^' Starts-with search.
'=' Exact matches.
'@' Full-text search. (Currently only supported Django MySQL backend.)
'$' Regex search.

      



In your case, just add

search_fields = ['=fieldname', 'otherfieldname']

      

to your administrator.

+6


source







All Articles