Search code examples
django-admin

Django admin search wildcard


I want to add a support for * wildcard in my django admin site.
Currently, if I have an instance named "abcde", and I search for it in the change list with abc (let's say I do an icontain filter) it will find a match.
However, when I use SQL wildcard * in the search field like: a*c, it finds nothing. How can I add this wildcard support?
Thank you.


Solution

  • You can implement your own ModelAdmin.get_search_results method to support this.

    Have a look at this implementation snippet: https://djangosnippets.org/snippets/3005/