需求:一对多,需要得到多的那边符合某些条件的实例数量。
topic.objects.all().annotate( post_count=Sum( Case(When(post__is_active=True,then=1),default=0,output_field=IntegerField())))