Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Admin filters for django admin

Django admin provides very basic view for applying filters on List pages but we have several uses cases where we want multi select, multi search, range filtering. These cases include applying filtering on related fields and reverse related fields as well

We explored several packages

  • https://github.com/modlinltd/django-advanced-filters
  • https://github.com/silentsokolov/django-admin-rangefilter
  • https://github.com/lukasvinclav/django-admin-numeric-filter

but none seems to fit our use cases well without fiddling with base model admin.

Are there alternatives to these ? If creating own custom filters how are you handling such uses cases ? - any ideas / tips / suggestion to start with ?

I did get some idea for search here - https://medium.com/@hakibenita/how-to-add-a-text-filter-to-django-admin-5d1db93772d8

  • for multiple options to search, planning to use comma separated values and then split that in backend
  • confused on how to implement for multi select choices
like image 281
user9724623 Avatar asked Oct 22 '25 07:10

user9724623


1 Answers

If you mean you want to filter through Boolean fields, go to admin.py and add list_filter in your modelAdmin. For example:

from django.contrib import admin

class YourModelAdmin(admin.ModelAdmin):
    list_filter = [
         "first_boolean_field",
         "second_bollean_field",
         "third_boolean_field"
    ]
    search_fields = (
        "field1",
        "field2",
    )

admin.site.register(YourModel, YourModelAdmin)

list_filter will allow you to filter by Boolean fields multiple times and search_field will allow you search by fields in the tuple.

like image 130
Yomna Mansour Avatar answered Oct 23 '25 22:10

Yomna Mansour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!