我有一个这样的查询
em =Employer.objects.filter(id=1).annotate(overall_value = Sum('companyreview__overallRating'))
em[0].overall_value
如您所见,我想对overallRating
所有具有.companyreview
employer
id = 1
上面的查询可以满足我的要求,但我确信有一种方法可以从Employer
实例中获取总和。
我怎样才能实现这个查询
em =Employer.objects.get(id=1)
rate = em.companyreview_set.all().annotate(overall_value = Sum('overallRating'))
rate.overall_value
?
谢谢