Django中的自定义过滤器(1.3)管理员

时间:2012-11-15 13:00:56

标签: django django-admin

如何在Django Admin中添加一个过滤器,该过滤器应该在模型仪表板右侧显示的过滤器中提供过滤结果。

更清楚:

class County (models.Model):
    status = models.CharField(max_length = 255, blank = True)
    name = models.CharField(max_length = 255, blank = True)


class County_info (models.Model):
   county = models.ForeignKey(County)
   city  = models.CharField(max_length = 255, blank = True)
   state = models.CharField(max_length = 255, blank = True)
   ......
   ......

在我的adim.py中,我必须为状态为“Production”的字段“county”显示模型“County_info”的过滤器。

list_filter = ['county__name', ] # will Show all data in that table. I need onlt the data which has status= 'production'

我该怎么做?

1 个答案:

答案 0 :(得分:0)

前几天我遇到了同样的问题,我发现它只能使用1.4:Admin filter documentation