Skip to main content

Django 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.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_autocompletefilter-0.0.7-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-autocompletefilter-0.0.7.linux-x86_64.tar.gz.

File metadata

  • Download URL: django-autocompletefilter-0.0.7.linux-x86_64.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6

File hashes

Hashes for django-autocompletefilter-0.0.7.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 31b71b57763387409b0e95b3db6102470e3325bbad20742f6423cafe5bd0de5b
MD5 fd32fbad769acf89d65ee5f6f07c71b1
BLAKE2b-256 df82cc8e28a356a209a69a68bf17cdc13fee4ddc8731eb23a977ec49831c0a53

See more details on using hashes here.

File details

Details for the file django_autocompletefilter-0.0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: django_autocompletefilter-0.0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.6

File hashes

Hashes for django_autocompletefilter-0.0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8dde706241b26cbca2ca03a6fc368e3ef6fd9b9781d4c70bb218fd92ce36202b
MD5 1c0f0afdc9ae5984714eab3d8c008be6
BLAKE2b-256 46841df911b2f53e1f1163ae38b02e3e3e04f35f9cb167935ef154e2838fc928

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page