Django Admin List Filter Dropdown

1.0.3 · maintenance · verified Sun Apr 12

django-admin-list-filter-dropdown is a Python library that enhances the Django administration interface by converting default list filters into dropdowns. This improves usability and reduces clutter in the sidebar, especially when a filter has numerous options. The current version is 1.0.3, released in 2019, suggesting a stable but less actively maintained project.

Warnings

Install

Imports

Quickstart

First, add `django_admin_listfilter_dropdown` to your `INSTALLED_APPS`. Then, in your `admin.py`, import the desired filter classes (e.g., `DropdownFilter`, `ChoiceDropdownFilter`, `RelatedDropdownFilter`) and use them within the `list_filter` tuple of your `ModelAdmin` class. This example demonstrates how to apply dropdown filters to a choice field, a foreign key field, and a boolean field.

# settings.py
INSTALLED_APPS = [
    # ... other apps
    'django_admin_listfilter_dropdown',
    # ...
]

# admin.py
from django.contrib import admin
from django.db import models # For example model
from django_admin_listfilter_dropdown.filters import DropdownFilter, ChoiceDropdownFilter, RelatedDropdownFilter


# Example Models
class Category(models.Model):
    name = models.CharField(max_length=100)

    def __str__(self):
        return self.name

class Product(models.Model):
    STATUS_CHOICES = [
        ('in_stock', 'In Stock'),
        ('out_of_stock', 'Out of Stock'),
        ('coming_soon', 'Coming Soon'),
    ]
    name = models.CharField(max_length=100)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    is_active = models.BooleanField(default=True)

    def __str__(self):
        return self.name


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('name', 'status', 'category', 'is_active')
    list_filter = (
        ('status', ChoiceDropdownFilter), # For fields with choices
        ('category', RelatedDropdownFilter), # For foreign key fields
        ('is_active', DropdownFilter), # For boolean fields, or custom SimpleListFilter
    )

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('name',)

view raw JSON →