Django admin list filter

I want to add a custom model method to the admin filter, however it does not work.

Foo example:

class Foo(models.Model): number = models.IntegerField() def big_enough(self): return self.number > 99 

now in the admin panel:

 class FooAdmin(admin.ModelAdmin): list_filter = ('number', 'big_enough') 

Failure, I get an error

Incorrect Configured in / admin / test / foo / 'FooAdmin.list_filter [0]' refers to the 'big_enough' field that is not in the 'Foo' model.

+7
django django-models django-admin
source share
2 answers

See this SO stream . It is not as simple as it seems. "

+8
source share

You cannot use the model method for this purpose. list_filter used to filter the django request set, which cannot make conscious use of bare functions.

+2
source share

All Articles