我想添加一个自定义模型方法到管理过滤器,但它失败了。
示例Foo:
class Foo(models.Model):
number = models.IntegerField()
def big_enough(self):
return self.number > 99现在,在管理面板中:
class FooAdmin(admin.ModelAdmin):
list_filter = ('number', 'big_enough')失败时,我会得到错误
/admin/ ImproperlyConfigured /Foo/ 'FooAdmin.list_filter‘处的测试引用了模型'Foo’中缺少的字段'big_enough‘。
发布于 2010-03-04 21:41:23
请参阅此SO thread。这并不像它看起来应该的那样简单。
发布于 2010-03-04 21:41:36
您不能将模型方法用于此目的。list_filter用于过滤django查询集,这不能有意义地利用裸函数。
https://stackoverflow.com/questions/2379607
复制相似问题