Reputation: 523
I'd like to execute such query using djagno models:
SELECT id, ( first+second+third ) FROM testTable
Without grouping. Was trying to find the solution using google but unsuccessfully.
Thanks in advance,
Upvotes: 1
Views: 150
Reputation: 1555
Use F() and annotate():
annotate()
from django.db.models import F # the sum of the three columns `first`, `second` and `third` will be # accessible as `.my_sum` results = my_model.objects.annotate( my_sum=F('first') + F('second') + F('third'), )
Upvotes: 8