[Fixed]-Django Group By query

1👍

You could user F objects to construct expressions inside Sum call

from django.db.models import F

...
.annotate(PrincipalRec=Sum(F('PrincipalRec')/100000), ... )

ATTN: This is not actually the same query that you asked, but Sum(xxx)/100000 should works same as Sum(xxx/100000) in case of decimal fields

And here is the same query, but using undocumented parts of django

from django.db.models import Value

...
.annotate(PrincipalRec=Sum('PrincipalRec')/Value(100000), ... )

Leave a comment