开发者

Django admin list filter

I want to add a custom model method to the admin filter, however it fails.

Example Foo:

class Foo(models.Model):
     number = models.IntegerField()
     def big_enough(self):开发者_开发问答
        return self.number > 99

now at the admin panel:

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

Fails, I get the error

ImproperlyConfigured at /admin/test/foo/ 'FooAdmin.list_filter[0]' refers to field 'big_enough' that is missing from model 'Foo'.


See this SO thread. It's not as easy as it feels like it should be.


You cannot use a model method for this purpose. list_filter is used to filter a django queryset, which cannot meaningfully utilize bare functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜