[Fixed]-Exact field search in the Django admin


a little late but i hope it still helps someone

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

'^' Starts-with search.
'=' Exact matches. (case-insensitive)
'@' Full-text search. (Currently only supported Django's MySQL backend.)
'$' Regex search. (Only with Django Rest Framework)

In your case, just add

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

to your admin.

Since Django 2.1 it is also possible to add lookups to the search fields (e.g. ‘fieldname__exact’). You can find infos in the Django Docs, as well as the possible Lookups

Leave a comment