django-autocompletefilter
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, or by any value you can search.
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), )
Filtering by any value
For a value that isn’t a foreign key (a text field, a JSON list, a computed lookup), or a foreign key you’d rather search your own way, subclass AutocompleteFilter: a SimpleListFilter whose choices are searched as you type instead of listed. Implement search(request, term), returning (value, label) pairs (a list, or a queryset of pairs, served in pages of page_size), and queryset() as usual. label(request, value) names the chosen value (default: the value itself). self.model_admin is there for search():
from autocompletefilter.admin import AutocompleteFilterMixin
from autocompletefilter.filters import AutocompleteFilter
class CountryFilter(AutocompleteFilter):
title = "country"
parameter_name = "country"
def search(self, request, term):
countries = (
self.model_admin.get_queryset(request)
.filter(country__icontains=term)
.order_by("country")
.values_list("country", flat=True)
.distinct()
)
return [(country, country) for country in countries]
def queryset(self, request, queryset):
if self.value():
return queryset.filter(country=self.value())
return queryset
class VisitAdmin(AutocompleteFilterMixin, admin.ModelAdmin):
list_filter = (CountryFilter,)
AutocompleteFilterMixin serves the searches at <changelist>/autocomplete-filter/<parameter_name>/ (URL name <app_label>_<model_name>_autocomplete_filter), for staff who may view the model, and only for the filters in the admin’s list_filter.
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.
Tested with Django 4.2 to 6.1.
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.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_autocompletefilter-0.2.0.tar.gz | 8.4 kB | With provenance | Details for django_autocompletefilter-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_autocompletefilter-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for django_autocompletefilter-0.2.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / django_autocompletefilter-0.2.0.tar.gz
| Download URL | django_autocompletefilter-0.2.0.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd0459a2c712f848d2f1dd4f990f0150281766eb8d7356697bce6236feb76d4b
|
|
BLAKE2b-256 checksum How to use checksums |
3ef414ec04418d6e16fc8eb312bd5f3a70c0e0a5446f447c3c8aded16d9bdc05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logRelease files / django_autocompletefilter-0.2.0-py3-none-any.whl
| Download URL | django_autocompletefilter-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13614d2bb14fb8e9b602a00b3852007c381c925cb31d08cd9556b30010b21582
|
|
BLAKE2b-256 checksum How to use checksums |
314ceb0286155568089439e7e86a568cdc72e931793af39c908c3b70f8470ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logSecurity for django-autocompletefilter 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_autocompletefilter-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.