gpt4 book ai didi

python - Django,查询相关字段: related field exists which meet conditions

转载 作者:太空宇宙 更新时间:2023-11-03 18:00:55 25 4
gpt4 key购买 nike

假设您有问答模型。

我希望问题的答案既不会被删除,也不会被审查。
(我想要以下函数返回 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)

关于python - Django,查询相关字段: related field exists which meet conditions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27699149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com