Skip to main content

Filtering and searching

Which fields a list can be filtered by, searched in and sorted by — declared on the admin class, rendered by the frontend without further configuration.

class ProductAdmin(ModelAdmin):
model = Product
filter_fields = ["status", "category", "price"]
search_fields = ["name", "description"]
ordering_fields = ["name", "price", "created_at"]
PageWhat it covers
Filter fieldsfilter_fields and the filters they generate
Custom filtersetsA FilterSet of your own for anything the defaults cannot express
Fulltext searchsearch_fields and per-resource ?search= filtering
Global searchThe cross-admin spotlight search and match highlighting
Ordering fieldsordering_fields and the default sort

What the frontend does with it​

Each filter arrives as a FilterSchema with a type and a format, and is rendered by the matching input component — a date range filter becomes DateRangeInput, a foreign key becomes an autocomplete. Filters marked always-on sit in the toolbar; the rest live in the filter drawer.

See also​