[英]Django, query for related field: related field exists which meet conditions
Suppose you have Question and Answer model. 假设您有问答模型。
I want questions that have answers which are neither deleted nor being reviewed. 我想要的问题答案既不会删除也不会被审查。
(I want questions that would return True for the following function.) (我想要以下函数返回True的问题。)
def has_active_answer(self):
return self.answers.not_deleted().filter(is_inreview=False).exists()
not_deleted() === filter(deleted=False) # if that makes difference
假设模型是Question
,并且有answers
字段:
Question.objects.filter(answers__deleted=False, answers__is_inreview=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.