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"]
| Page | What it covers |
|---|---|
| Filter fields | filter_fields and the filters they generate |
| Custom filtersets | A FilterSet of your own for anything the defaults cannot express |
| Fulltext search | search_fields and per-resource ?search= filtering |
| Global search | The cross-admin spotlight search and match highlighting |
| Ordering fields | ordering_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
- Aggregations — the same filters applied to aggregate queries
- SchemaList — the list view these feed