Skip to main content

Django autocomplete light filters for django admin

Project description


Django-autocomplete-light filters for django admin.

default select2 widget

alt text

widget with title as placeholder

alt text


This is extension for django-autocomplete-light so you need to install and configure it too.

Here will be minimum setup for example.

Refer to for more detailed instructions.


  • Install using pip

    pip install django-autocomplete-light dal_admin_filters
  • Update INSTALLED_APPS, you need too put django-autocomplete-light before admin

        ... other stuff there ...


  • Create autocomplete view
    • Let our models look like this
      class Country(models.Model):
          name = models.CharField(max_length=100, unique=True)
          def __str__(self):
      class Person(models.Model):
          name = models.CharField(max_length=100, unique=True)
          from_country = models.ForeignKey(Country)
          def __str__(self):
    • Then autocomplete view for country selection will be similar to next
      from dal import autocomplete
      from your_countries_app.models import Country
      class CountryAutocomplete(autocomplete.Select2QuerySetView):
          def get_queryset(self):
              # Don't forget to filter out results depending on the visitor !
              if not self.request.user.is_authenticated():
                  return Country.objects.none()
              qs = Country.objects.all()
              if self.q:
                  qs = qs.filter(name__istartswith=self.q)
              return qs
  • Register view in
    from your_countries_app.views import CountryAutocomplete
    urlpatterns = [
  • Use filter in your
    from django.contrib import admin
    from your_countries_app.models import Country, Person
    from dal_admin_filters import AutocompleteFilter
    class CountryAdmin(admin.ModelAdmin):
    class CountryFilter(AutocompleteFilter):
        title = 'Country from'                    # filter's title
        field_name = 'from_country'           # field name - ForeignKey to Country model
        autocomplete_url = 'country-autocomplete' # url name of Country autocomplete view
    class CountryPlaceholderFilter(AutocompleteFilter):
        title = 'Country from'                    # filter's title
        field_name = 'from_country'           # field name - ForeignKey to Country model
        autocomplete_url = 'country-autocomplete' # url name of Country autocomplete view
        is_placeholder_title = True               # filter title will be shown as placeholder
    class CountryCustomPlaceholderFilter(AutocompleteFilter):
        title = 'Country from'                    # filter's title
        parameter_name = 'from_country'           # field name - ForeignKey to Country model
        autocomplete_url = 'country-autocomplete' # url name of Country autocomplete view
        widget_attrs = {
            'data-placeholder': 'Filter by country name'
    class PersonAdmin(admin.ModelAdmin):
        class Media:    # Empty media class is required if you are using autocomplete filter
            pass        # If you know better solution for altering from filter instance
                        #   - please contact me or make a pull request
        list_filter = [CountryFilter]

If setup is done right, you will see the Select2 widget in admin filter in Person's changelist view.

Define dependencies between filters (forward)

  • Define forwards in the filter (example from the demo_project)

    from dal import forward
    class PersonFilter(AutocompleteFilter):
        autocomplete_url = 'person-autocomplete'
        title = 'Owner'
        field_name = 'owner'
        forwards = [
                'from_country__id__exact',  # Field name of filter input
                'country_id'  # Field name passed to the autocomplete_url endpoint


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dal-admin-filters, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size dal_admin_filters-1.0.2-py2-none-any.whl (31.2 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size dal_admin_filters-1.0.2-py3-none-any.whl (31.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size dal_admin_filters-1.0.2.tar.gz (31.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page