2👍
✅
You are trying to groupby author’s name so remove the avg_depth
in the values_list. annotate
will add the Avg score/avg_depth
for each author. You can do like:
result = Book.objects.filter(author__name__in=['A','B','C']).values_list('author__name').annotate(Avg('score'))
Here values_list
is used to groupby author’s name and Avg('score')
will calculate the average score for each author which then would be annotated to each author using annotate()
Source:stackexchange.com