If you are using a version of Django greater than 2.0, you can try using the built-in autocomplete fields for this purpose.
By default, the administrator uses the select () interface for these fields. Sometimes you donβt want to take overhead when selecting all related instances to display in the drop-down list.
Input Select2 is similar to the default input, but comes with a search function that loads parameters asynchronously
There is a simple application that does this:
To install, use: pip install django-admin-autocomplete-filter
Then add admin_auto_filters to your INSTALLED_APPS inside the settings.py of your project.
Say we have the following models:
class Artist(models.Model): name = models.CharField(max_length=128) class Album(models.Model): name = models.CharField(max_length=64) artist = models.ForeignKey(Artist, on_delete=models.CASCADE) cover = models.CharField(max_length=256, null=True, default=None)
And you want to filter the results in Album Admin based on the artist, then you can define the search fields in Artist and then define the filter as:
from admin_auto_filters.filters import AutocompleteFilter class ArtistFilter(AutocompleteFilter): title = 'Artist'
After completing these steps, you can see the filter as:


source share