【发布时间】:2011-08-27 05:41:51
【问题描述】:
我通常使用类似“Tag.object.annotate(num_post=Count('post')).filter(num_post__gt=2)”的东西来获取超过 2 个帖子的标签。我想获取具有字段值(例如 post.published=True)的帖子数量并对其进行注释,以便我获得已发布帖子数量大于某个值的标签。我该怎么做?
编辑:
我想要的不是过滤带注释的对象。我想要的是这样的:Tag.objects.annotate(num_post=Count("posts that have published field set to true!"))。我想学习的是,如何将已发布字段设置为 true 的帖子在 Count 函数中。
【问题讨论】: