昨天,当我在Django中为我的管理站点编写特殊的过滤器时,我遇到了这个问题。
我有3个型号:
class ShopInfo(models.Model):
name = models.CharField(max_length=200)
class Keyword(models.Model):
keyword1 = models.CharField(max_length=4096, blank=True)
product = models.ManyToManyField(Products)
class Products(models.Model):
shop = models.ForeignKey(ShopInfo)
In Admin site, on the Keyword edit page, I want create a filter for Keywords by shop.
In other words, I want to see full list of shops in filter list on the right of page, when you click on that we will choose the Keywords belonged this shop. 发布于 2012-05-23 07:11:27
为此,您不需要任何自定义的FilterSpecs。您可以在ModelAdmin的list_filter属性中使用django的连接语法。例如:
class KeywordAdmin(admin.ModelAdmin):
list_filter = ['product__shop']https://stackoverflow.com/questions/10395755
复制相似问题