如果特定主题有未解决的问题,我试图获取 True 或 False 。
我尝试了以下方法:
以下代码对我不起作用。看来我无法将<type 'Count'>
与<type 'int'>
进行比较。
Topic.objects.all().annotate(has_unanswered_questions = Count('question', filter = Q(question__status.text='open')) > 0)
答案 0 :(得分:1)
您需要过滤注释:
Topic.objects.all()\
.annotate(unanswered_questions=Count('question', filter=Q(question__status.text='open')))\
.filter(unanswered_questions__gt=0)