Skip to main content

django-admin-autocomplete-list-filter

Ajax autocomplete list filter helper for Django admin. Uses Django’s built-in autocomplete widget! No extra package or install required!

After

Installation and Usage

$ pip install django-admin-autocomplete-list-filter2

Add djaa_list_filter2 to INSTALLED_APPS in your settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'djaa_list_filter2',           
]

Now, let’s look at this example model:

# models.py

from django.conf import settings
from django.db import models


class Post(models.Model):
    category = models.ForeignKey(to='Category', on_delete=models.CASCADE, related_name='posts')
    author = models.ForeignKey(to=settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='posts')
    title = models.CharField(max_length=255)
    body = models.TextField()
    tags = models.ManyToManyField(to='Tag', blank=True)

    def __str__(self):
        return self.title


class Category(models.Model):
    title = models.CharField(max_length=255)

    def __str__(self):
        return self.title


class Tag(models.Model):
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name

We have 2 ForeignKey fields and one ManyToManyField to enable autocomplete list filter feature on admin. All you need is to inherit from AjaxAutocompleteListFilterModelAdmin which inherits from Django’s admin.ModelAdmin.

Now we have an extra ModelAdmin method: autocomplete_list_filter. Uses Django Admin’s search_fields logic. You need to enable search_fields in the related ModelAdmin. To enable completion on Category relation, CategoryAdmin should have search_fields that’s it!

from django.contrib import admin

from djaa_list_filter2.admin import (
    AjaxAutocompleteListFilterModelAdmin,
)

from .models import Category, Post, Tag


@admin.register(Post)
class PostAdmin(AjaxAutocompleteListFilterModelAdmin):
    list_display = ('__str__', 'author', 'show_tags')
    autocomplete_list_filter = ('category', 'author', 'tags')

    def show_tags(self, obj):
        return ' , '.join(obj.tags.values_list('name', flat=True))


@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    search_fields = ['title']
    ordering = ['title']


@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    search_fields = ['name']
    ordering = ['name']

Development

You are very welcome to contribute, fix bugs or improve this project. We hope to help people who needs this feature. We made this package for our company project. Good appetite for all the Django developers out there!

License

This project is licensed under MIT


Contributor(s)


TODO

  • Add unit tests
  • Improve JavaScript code :)

Change Log

2025-06-14

  • Bump version: 1.0.3
  • Renamed to djaa_list_filter2 to avoid conflicts with other versions

2022-07-29

  • Bump version: 1.0.2
  • Fixed Django 4 compatibility by removing usage of ugettext_lazy

2021-09-03

  • Bump version: 1.0.1
  • Fixed css conflict with Django theme

2021-08-17

2019-10-25

  • Remove f-string for older Python versions, will change this on 1.0.0 version

2019-10-19

  • Bump version: 0.1.2
  • Add Python 3.5 supports, thanks to Peter Farrel
  • Add animated gif :)
  • Add future warning for f-strings

2019-10-11

  • Add ManyToManyField support
  • Initial release

2019-10-07

  • Init repo...

Metadata

Release files for django-admin-autocomplete-list-filter2 1.0.3

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-admin-autocomplete-list-filter2 1.0.3
File Size Uploaded Provenance
django_admin_autocomplete_list_filter2-1.0.3.tar.gz 9.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-admin-autocomplete-list-filter2 1.0.3
File Interpreter ABI Platform
django_admin_autocomplete_list_filter2-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / django_admin_autocomplete_list_filter2-1.0.3.tar.gz

Download URL django_admin_autocomplete_list_filter2-1.0.3.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
df68491c5556925423f39aeff0909e71bb066b1b9cabda27c72a64c9bbac6516
BLAKE2b-256 checksum
How to use checksums
c7deff9aa326148987e72fa236b0799c713d5a8c256faf633028de68f769fac8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / django_admin_autocomplete_list_filter2-1.0.3-py3-none-any.whl

Download URL django_admin_autocomplete_list_filter2-1.0.3-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d7ca048d9153bb22bc94994e108a26786edb1193463ee3f28515e8a56b3eef7
BLAKE2b-256 checksum
How to use checksums
6e097ed28bc02b959d8bb3613a5670285309cc069267be54b969cae3afb9fe31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for django-admin-autocomplete-list-filter2 1.0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files No provenance

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