Skip to main content

Filter fields

Declares which fields a list can be filtered by.

Each entry becomes a FilterSchema in the view schema, and the frontend renders the matching input — you do not write filter UI.

Declaration​

from habarico import ModelAdmin

from .models import Product


class ProductAdmin(ModelAdmin):
model = Product
filter_fields = [
"name",
"status",
"category",
"brand",
"stock",
"price",
"created_at",
]
fields = ["name", "sku", "description", "status", "category", "brand", "stock", "price", "created_at"]

Generated schema​

The filter's type and format are derived from the underlying django-filter filter:

FieldFilterRendered as
CharFieldtextTextInput
model choiceschoiceChoicesInput
ForeignKeymodel choiceSchemaReferenceInput autocomplete
numeric / decimalrangeSchemaRangeInput
date, datetimerangeDateRangeInput
BooleanFieldbooleana tri-state toggle, so “either” is expressible

A relation filter without a resolvable reference degrades to a choice filter rather than failing.

tip

Filters split into two groups on screen: the always-on ones sit in the toolbar, the rest live in a drawer behind the filter button. Which is which is a per-view decision — see List view schema generators.

See also​