Jim*_*Jim 5 python django django-orm
作为我的模型类之一的成员函数,我有一个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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5491 次 |
| 最近记录: |