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.
Usage
Install the package, for example from PyPi:
pip install django-autocompletefilter
Add autocompletefilter to your INSTALLED_APPS setting.
Create and register a model admin for the model you want to filter by. Ensure it has search_fields specified for autocomplete to work.
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
Hashes for django_autocompletefilter-0.0.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1d43c2c5cabcf0b657ab03dcde6773ad1bb045dec6ea90164394b5198e7ff5c |
|
MD5 | 644464136c2a326f5e4122c9351536a9 |
|
BLAKE2b-256 | 2b103775f2e14a5c10261898491855cb09046012ba49e63e7fa0783f4135371a |
Hashes for django_autocompletefilter-0.0.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2225053538a3621260016c228d439aa5fcf37eacc8c17a7de9bed85393a255b3 |
|
MD5 | 2348960a1ac5b88d922c5fb8be762e95 |
|
BLAKE2b-256 | e946ccd6c2672321c17bee9a72b7907d646b26b9de825e6460fdb2547171be89 |