I'm trying to do a query and I want to group by several fields. Some of those fields are foreign keys. When I get my query set back, I would like those foreign keys to be objects of their respective models. The only way I have found to group by a queryset is values('model1', 'model2', 'somefield')
. When I do this, though, the values I get from those fields are the IDs of those objects.
What I'm looking for is an equivalent query set to this:
SELECT model1, model2, somefield, sum(something) FROM table WHERE (conditions here) GROUP BY model1, model2, somefield
And I would like model1
, model2
to actually be model objects instead of just IDs.
Any good way to do this?
Thanks