Why is django group on wrong field? annotation ()
Why Django Group by id field? Here is the request:
MyModel.objects\
.filter(
status=1,
created__gte=datestart,
created__lte=dateend)\
.values('terminal_id')\
.annotate(
total_pa=Sum('amount'),
total_ar=Sum('amount_result')).query
But it orders and groups by the field pk.
... GROUP BY payment
. id
ORDER BY payment
. id
...
Instead
... GROUP BY payment
. terminal_id
ORDER BY payment
. terminal_id
...
+3
source to share