I am trying to GROUP BY with Django ORM:
sub = (
Participant.objects
.values('category')
.annotate(
average=Avg(F('price')),
)
)
It works as expected BUT the queryset does not contains instances of the model anymore. If contains dicts
because values()
has been called.
How can do a group by query and get a regular queryset (with model instances)?