Skip to main content

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.

Metadata

Release files for django-autocompletefilter 0.0.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-autocompletefilter 0.0.9
File Size Uploaded
django_autocompletefilter-0.0.9.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-autocompletefilter 0.0.9
File Interpreter ABI Platform
django_autocompletefilter-0.0.9-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 kB

Release files / django_autocompletefilter-0.0.9.tar.gz

Download URL django_autocompletefilter-0.0.9.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d1d43c2c5cabcf0b657ab03dcde6773ad1bb045dec6ea90164394b5198e7ff5c
BLAKE2b-256 checksum
How to use checksums
2b103775f2e14a5c10261898491855cb09046012ba49e63e7fa0783f4135371a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / django_autocompletefilter-0.0.9-py3-none-any.whl

Download URL django_autocompletefilter-0.0.9-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2225053538a3621260016c228d439aa5fcf37eacc8c17a7de9bed85393a255b3
BLAKE2b-256 checksum
How to use checksums
e946ccd6c2672321c17bee9a72b7907d646b26b9de825e6460fdb2547171be89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.0.9 This release

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page