作为我的模型类之一的成员函数,我有一个is_visible(self, user)
返回布尔值的方法。根据定义,它需要请求用户(DjangoUser
模型)作为输入。
我希望能够根据对此方法的响应来过滤查询集。如何使用此函数作为查询集过滤器?
对于上下文,这是我的is_visible
执行:
def is_visible(self, user):
if self.status.status_internal == "open":
return True
if self.owner == user:
return true
participations = Participation.objects.filter(event__id=self.id, participant__id=user.id)
if len(participations) > 0:
return True
if self.status.status_internal == "invite":
return True
return False
您不能使用 python 函数来过滤查询集。您必须“复制”此代码并使用过滤您的对象Q 对象 https://docs.djangoproject.com/en/dev/topics/db/queries/#complex-lookups-with-q-objects.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)