【发布时间】:2023-03-30 22:27:01
【问题描述】:
我想计算批准的 cmets 的数量?
news_list = News.objects.all()\
.annotate(
comments_count=Count(
'comments__id',
comments__status=COMMENT_STATUS_APPROVED
)
)
但计数功能的第二个条件不起作用。如何过滤annotate-function
【问题讨论】:
-
在 Django 中无法过滤注释。您将不得不使用自定义 SQL。此博客条目可能有用:timmyomahony.com/blog/filtering-annotations-django
-
@Leistungsabfall 感谢您提供此链接!我已将我的查询集更改为使用额外选择。
标签: python django django-models django-queryset