Skip to main content

Django 2.0 ModelAdmin list_filter with autocomplete widget.

Project description

A django application that lets you use the built in autocomplete function of the django admin to filter in admin list views by foreign key relations.

https://pbs.twimg.com/media/DgmzYLbW4AA9oL3.jpg:large

Usage

  1. Install the package, for example from PyPi:

    pip install django-autocompletefilter
    
  2. Add autocompletefilter to your INSTALLED_APPS setting.

  3. Create and register a model admin for the model you want to filter by. Ensure it has search_fields specified for autocomplete to work.

  4. In your second model admin, use the AutocompleteFilterMixin on your class and add the desired foreign key attribute to filter by to the list_filter items by using the AutocompleteListFilter class:

    from autocompletefilter.admin import AutocompleteFilterMixin
    from autocompletefilter.filters import AutocompleteListFilter
    
    class FooAdmin(AutocompleteFilterMixin, admin.ModelAdmin):
        list_filter = (
            ('bar', AutocompleteListFilter),
        )
    

Status of this project

This project is currently using a rather hacky way to implement this. Caution is advised when using it.

Using multiple autocomplete filters on the same page does work.

Currently only tested on Python 3.6

Contributing

All suggestions are welcome. Especially about ways to make this cleaner.

Common issues

  • Reverse for ‘<app_name>_<model_name>_autocomplete’ not found.

    You must register a model admin with search_fields for the model you want to look up.

  • The results could not be loaded.

    You likely forgot to specify search_fields on your model admin for the model you want to look up.

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 django-autocompletefilter, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size django_autocompletefilter-0.0.6-py2.py3-none-any.whl (7.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size django-autocompletefilter-0.0.6.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page