List Filters

_images/filters.png

Input Text Filters

Idea taken from this medium article.

Baton defines a custom InputFilter class that you can use to create text input filters and use them as any other list_filters, for example

# your app admin

from baton.admin import InputFilter

class IdFilter(InputFilter):
    parameter_name = 'id'
    title = 'id'

    def queryset(self, request, queryset):
        if self.value() is not None:
            search_term = self.value()
            return queryset.filter(
                id=search_term
            )


class MyModelAdmin(admin.ModelAdmin):
    list_filters = (
        'my_field',
        IdFilter,
        'my_other_field',
    )

Just define in the queryset method the logic used to retrieve the results.