Skip to Content
FeaturesModulesDjango AdminFilters

Filters Guide

FilterConfig declares a list filter by field and type. Each type resolves to a stock Django filter, a filter from django_cfg.modules.django_admin.filters, or a range filter from django-admin-rangefilter (a base dependency). No manual class definitions for common patterns.

Two Styles, One Field

list_filter accepts both the new declarative style and the classic raw style. Mix them freely — they resolve to the same Django format under the hood.

from django.contrib import admin from django_cfg.modules.django_admin import AdminConfig, FilterConfig config = AdminConfig( model=Payment, list_filter=[ # Declarative — new FilterConfig(field='status', type='choices_dropdown'), FilterConfig(field='created_at', type='range_date'), FilterConfig(field='amount', type='range_numeric'), FilterConfig(field='user', type='autocomplete'), # Raw — still works 'currency', MyCustomFilter, ('is_test', admin.BooleanFieldListFilter), ], )

FilterConfig Reference

from django_cfg.modules.django_admin import FilterConfig FilterConfig( field='status', # Model field name type='choices_dropdown', # One of 17 FilterType values (see table below) title=None, # Custom sidebar label (SimpleListFilter types only) filter_class=None, # Raw filter class — bypasses type lookup )

FilterType values

F = django_cfg.modules.django_admin.filters, rangefilter = rangefilter.filters.

typeClassUse caseNote
choices_dropdownF.ChoicesDropdownFilterField with choices=, a <select>
choices_dropdown_multipleF.ChoicesDropdownFilterSamefallback: single choice
choices_checkboxadmin.ChoicesFieldListFilterField choices as a link listfallback: single choice
choices_radioadmin.ChoicesFieldListFilterField choices as a link list
booleanadmin.BooleanFieldListFilterBooleanField: All / Yes / No
related_dropdownF.RelatedDropdownFilterForeignKey, a <select>
related_dropdown_multipleF.RelatedDropdownFilterSamefallback: single choice
related_checkboxadmin.RelatedFieldListFilterForeignKey as a link listfallback: single choice
autocompleteF.AutocompleteFilterForeignKey with a select2 search box
autocomplete_multipleF.AutocompleteFilterSamefallback: single choice
range_numericrangefilter.NumericRangeFilterNumeric from / to
sliderrangefilter.NumericRangeFilterNumeric from / tofallback: two number boxes, no slider
range_daterangefilter.DateRangeFilterDateField from / to
range_datetimerangefilter.DateTimeRangeFilterDateTimeField from / to
textF.TextFilterText box, <field>__icontains
dropdownF.DropdownFilter (SimpleListFilter)Custom queryset, a <select>
dropdown_multipleF.DropdownFilter (SimpleListFilter)Samefallback: single choice

A type with a note has no exact stock equivalent: the nearest filter is used and a FilterFallbackWarning names it when the admin class is built. Pick a type without a note to silence it.

FieldListFilter-based types are bound to a model field automatically. SimpleListFilter-based types (dropdown, dropdown_multiple) need you to subclass them and implement lookups() and queryset() — use filter_class for those.


Examples by Use Case

Status / Choice field

from django_cfg.modules.django_admin import AdminConfig, FilterConfig config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='status', type='choices_dropdown'), ], )

Works with any CharField / IntegerField that has choices= defined on the model.

ForeignKey — dropdown

config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='customer', type='related_dropdown'), FilterConfig(field='warehouse', type='related_dropdown'), ], )
config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='customer', type='autocomplete'), ], )

autocomplete and autocomplete_multiple require the related model’s admin to define search_fields. Without it Django raises AttributeError at runtime.

# Required: the related admin must have search_fields @admin.register(Customer) class CustomerAdmin(PydanticAdmin): config = AdminConfig( model=Customer, search_fields=['name', 'email'], # ← required ... )

Numeric range

config = AdminConfig( model=Transaction, list_filter=[ FilterConfig(field='amount', type='range_numeric'), ], )

Renders two inputs: From and To. Works with IntegerField, DecimalField, FloatField.

Numeric slider

config = AdminConfig( model=Product, list_filter=[ FilterConfig(field='price', type='slider'), ], )

Renders the same two number boxes as range_numeric (there is no slider on the stock admin) and emits a FilterFallbackWarning. Prefer range_numeric.

Date range

config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='created_at', type='range_date'), FilterConfig(field='shipped_at', type='range_datetime'), ], )

Boolean field

config = AdminConfig( model=User, list_filter=[ FilterConfig(field='is_active', type='boolean'), FilterConfig(field='is_staff', type='boolean'), ], )

Renders Django’s All / Yes / No links.

Text search in sidebar

config = AdminConfig( model=Product, list_filter=[ FilterConfig(field='name', type='text'), ], )

Adds a text box that filters with <field>__icontains.

config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='status', type='choices_radio'), 'category', # a ForeignKey: Django's related link list ], )

choices_checkbox and related_checkbox render the same single-choice link lists (with a FilterFallbackWarning); there is no multi-select checkbox filter.


Custom filter class

For business-logic filters (custom queryset(), dynamic choices), pass the class directly via filter_class:

from django.contrib import admin class RecentOrdersFilter(admin.SimpleListFilter): title = 'time range' parameter_name = 'range' def lookups(self, request, model_admin): return [ ('24h', 'Last 24 hours'), ('7d', 'Last 7 days'), ('30d', 'Last 30 days'), ] def queryset(self, request, queryset): from datetime import timedelta from django.utils import timezone now = timezone.now() if self.value() == '24h': return queryset.filter(created_at__gte=now - timedelta(hours=24)) if self.value() == '7d': return queryset.filter(created_at__gte=now - timedelta(days=7)) if self.value() == '30d': return queryset.filter(created_at__gte=now - timedelta(days=30)) return queryset config = AdminConfig( model=Order, list_filter=[ FilterConfig(field='range', filter_class=RecentOrdersFilter), # Or just pass the class directly — both work: # RecentOrdersFilter, ], )

When filter_class is a SimpleListFilter subclass it is returned as-is. When it is a FieldListFilter subclass it is returned as ('field', FilterClass).


Simple string filters

Django auto-detects the filter type from the model field:

config = AdminConfig( model=Order, list_filter=['status', 'created_at', 'is_active', 'customer'], )
Field typeAuto-detected filter
BooleanFieldYes / No / All
CharField with choicesChoice filter
ForeignKeyRelated object list
DateField / DateTimeFieldDate drill-down
IntegerFieldExact value

Facet counts

Django 5.0+ shows the number of matching records next to each filter option. The stock default, ModelAdmin.show_facets = ShowFacets.ALLOW, puts a “Show counts” toggle above the filters. To always show them, set it in the config:

config = AdminConfig( model=Order, list_filter=["status"], show_facets=True, # sets ShowFacets.ALWAYS on the admin class )

Since 2.4.100 show_facets=True becomes ShowFacets.ALWAYS. In 2.4.1 and earlier it set a plain True, which Django (comparing by identity) read as neither value: the counts and the toggle disappeared. On those versions set show_facets = ShowFacets.ALWAYS on the class.


Date hierarchy

For date-based drill-down navigation above the list:

config = AdminConfig( model=Order, date_hierarchy='created_at', list_filter=[ FilterConfig(field='status', type='choices_dropdown'), ], )

Complete example

from django.contrib import admin from django_cfg.modules.django_admin import ( AdminConfig, BadgeField, CurrencyField, DateTimeField, FilterConfig, UserField, ) from django_cfg import Icons from django_cfg.modules.django_admin.base import PydanticAdmin config = AdminConfig( model=Payment, list_display=['id', 'user', 'amount', 'status', 'created_at'], display_fields=[ BadgeField( name='status', label_map={ 'pending': 'warning', 'processing': 'info', 'completed': 'success', 'failed': 'danger', }, ), UserField(name='user', header=True), CurrencyField(name='amount', currency='USD', precision=2), DateTimeField(name='created_at', show_relative=True), ], list_filter=[ FilterConfig(field='status', type='choices_dropdown'), FilterConfig(field='created_at', type='range_date'), FilterConfig(field='amount', type='range_numeric'), FilterConfig(field='user', type='autocomplete'), 'currency', ], date_hierarchy='created_at', search_fields=['id', 'user__email'], select_related=['user', 'currency'], ordering=['-created_at'], ) @admin.register(Payment) class PaymentAdmin(PydanticAdmin): config = config

Performance tips

Index filtered fields — every field in list_filter should have a DB index:

class Payment(models.Model): status = models.CharField(choices=STATUS_CHOICES, db_index=True) created_at = models.DateTimeField(db_index=True) amount = models.DecimalField(...)

Prefer autocomplete over dropdown for large FK tables:

# Bad: Loads all customers into the dropdown FilterConfig(field='customer', type='related_dropdown') # Good: Lazy search — fast even with millions of records FilterConfig(field='customer', type='autocomplete')

Use select_related to avoid N+1 on FK filter options:

config = AdminConfig( model=Order, select_related=['customer', 'warehouse'], list_filter=[ FilterConfig(field='customer', type='related_dropdown'), ], )

Next Steps

TAGS: filters, list_filter, FilterConfig, FilterType, dropdown, autocomplete, range, rangefilter

Last updated on