Skip to content

Admin Filters

filters

TextInputFilter

Bases: SimpleListFilter

Base filter that renders a free-text input instead of a dropdown.

Subclass this and override queryset to implement the actual filtering logic. The lookups method returns a dummy value to ensure Django renders the filter in the sidebar.

Example
class NameFilter(TextInputFilter):
    title = 'Name'
    parameter_name = 'name'

    def queryset(self, request, queryset):
        if self.value():
            return queryset.filter(name__icontains=self.value())
        return queryset

SearchInFilter

Bases: SimpleListFilter

Dropdown filter that lets users choose which field to search in.

Used internally by EnhancedAdminMixin when search_in_choices is set. The selected value narrows the admin search to a single field lookup.

Attributes:

Name Type Description
lookup_choices

List of (field_lookup, label) tuples populated from EnhancedAdminMixin.search_in_choices.

MultiSelectFilterMixin

Base mixin for multi-select admin filters using <select multiple>.

Provides common functionality for filters that allow multiple values to be selected and filtered with OR logic (field__in lookup). Subclasses should also inherit from FieldListFilter and implement lookups and __init__.

options property

Get all available options for the select element

selected_values property

Get currently selected values

other_params property

Get other GET parameters (excluding this filter's parameter)

clear_url property

Build URL to clear this filter

expected_parameters()

Return list of expected URL parameters for this filter

get_selected_values()

Get list of currently selected values from URL parameters

queryset(request, queryset)

Apply filtering with __in lookup for selected values

choices(changelist)

For compatibility with FieldListFilter. Return empty generator since we use a custom template.

MultiSelectAllValuesFieldFilter(field, request, params, model, model_admin, field_path)

Bases: MultiSelectFilterMixin, FieldListFilter

Multi-select filter populated from all distinct values of a field.

Queries the database for unique non-null values and renders them as a multi-select widget. Selected values are combined with OR logic.

Example
class MyAdmin(admin.ModelAdmin):
    list_filter = [
        ('last_name', MultiSelectAllValuesFieldFilter),
    ]

lookups(request, model_admin)

Get all distinct values from database

MultiSelectChoicesFieldFilter(field, request, params, model, model_admin, field_path)

Bases: MultiSelectFilterMixin, FieldListFilter

Multi-select filter for fields with predefined choices.

Uses the field's choices attribute to populate the options. Works correctly when stored values differ from display labels (e.g. ('SE', 'Software Engineer')).

Example
class MyAdmin(admin.ModelAdmin):
    list_filter = [
        ('position', MultiSelectChoicesFieldFilter),
    ]

lookups(request, model_admin)

Return field's defined choices

MultiSelectRelatedFieldFilter(field, request, params, model, model_admin, field_path)

Bases: MultiSelectFilterMixin, FieldListFilter

Multi-select filter for ForeignKey and ManyToManyField relationships.

Populates options from the related model's queryset, using each object's __str__ as the display label and its primary key as the value.

Example
class MusicianAdmin(admin.ModelAdmin):
    list_filter = [
        ('person', MultiSelectRelatedFieldFilter),
    ]

lookups(request, model_admin)

Query related model for available objects

queryset(request, queryset)

Apply filtering with proper type conversion for PKs