我有一个模型,指向一个通用关系。这可以是联系对象或客户对象。通用关系上的Django过滤器
class Unsubscribe(models.Model):
"""
Notes:
See: http://www.screamingatmyscreen.com/2012/6/django-and-generic-relations/
"""
content_type = models.ForeignKey(ContentType, help_text="Represents the name of the model")
object_id = models.PositiveIntegerField(help_text="stores the object id")
content_object = generic.GenericForeignKey('content_type', 'object_id')
reason = models.CharField(max_length=60)
request_made = models.DateTimeField(auto_now_add=True,
help_text="Shows when object was created.")
class Meta:
ordering = ['-request_made']
我想列出所有未订阅的退订客户和仅为用户的联系人。
queryset = Unsubscribe.objects.filter()
以上给了我所有退订的客户和联系人的任何用户通常我会做解决这个....
queryset = Unsubscribe.objects.filter(user=request.user)
然而,退订对象没有用户,而且均与客户联系人呢。
那么如何过滤通用关系呢?
我累了,这也查询集= Unsubscribe.objects.filter(content_object__contact_owner = self.request.user),但它指出content_object不存在,当它确实。 – GrantU
我不认为'content_obect __...'是有效的字段查找,请尝试使用我指定的。 – Rohan