私はそのようなクエリを持っています
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
?
ありがとう