I need to do the following query in Django:
SELECT sum(T.width * T.height) as amount
FROM triangle T
WHERE T.type = 'normal'
GROUP BY S.color
How can I do this using your django ORM? I tried this:
Triangle.objects.filter(type='normal').\
extra(select={'total':'width*height'}).\
values('id', 'total').\
annotate(amount=Sum('total'))
but it does not work, the error I get is that TOTAL is not in the model. How can I fix it?