我想通过外键属性在管理员更改列表中添加过滤器,例如,对外键属性的Django管理员过滤器
class Address(model.Models):
street = models.CharField(max_length=25)
city = models.CharField(max_length=25)
country = models.CharField(max_length=25)
class Customer(models.Model):
name = models.CharField(max_length=25)
address = models.ForeignKey(Address)
让我们在客户管理变更列表我要显示的城市和国家的过滤器说,(所以告诉我在一个特定国家或城市的所有客户)。
但是,标准的list_filter()功能似乎只允许按字段直接在模型上进行过滤,而不是对其外键进行过滤。我已经试过:
list_filter = ("address__country",)
或
list_filter = ("address.country",)
但我总是得到相同类型的错误:
'address__country' is not a callable or an attribute
任何建议将受到欢迎。是否有一些特殊的命名约定/语法允许过滤FK属性?
http://stackoverflow.com/questions/2065036/django-list-filter-and-foreign-key-fields – 2010-03-04 14:10:08