0

我用夹层。它有型号:

class AssignedKeyword(Orderable):
    """
    A ``Keyword`` assigned to a model instance.
    """

    keyword = models.ForeignKey("Keyword", related_name="assignments")
    content_type = models.ForeignKey("contenttypes.ContentType")
    object_pk = models.IntegerField()
    content_object = GenericForeignKey("content_type", "object_pk")

    class Meta:
        order_with_respect_to = "content_object"

    def __unicode__(self):
        return unicode(self.keyword)

我想获取所有唯一的 AssignedKeyword 模型实例,其中content_object字段类型为Post. 如何按字段类型过滤查询集?

4

1 回答 1

0

答案很简单:

AssignedKeyword.objects.filter(content_type=ContentType.objects.get(name='Product'))
于 2013-02-26T15:15:35.513 回答