Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin filter using method

Tags:

django-admin

How can make custom filter in django admin. I mean write a method do some calculation in it and add it to list_filter.

like image 314
Jitendra Srivastava Avatar asked Jan 24 '13 16:01

Jitendra Srivastava


People also ask

What is List_filter in Django?

For Django 1.4-1.7, list_filter allows you to use a subclass of SimpleListFilter . It should be possible to create a simple list filter that lists the values you want.

What is filter method in Django?

The filter() method is used to filter you search, and allows you to return only the rows that matches the search term.

Can you filter by property Django?

Nope. Django filters operate at the database level, generating SQL. To filter based on Python properties, you have to load the object into Python to evaluate the property--and at that point, you've already done all the work to load it.


1 Answers

You can use a class inheriting from django.contrib.admin.SimpleListFilter like as described at here.

like image 178
Ricardo Falasca Avatar answered Sep 21 '22 10:09

Ricardo Falasca