Me gustaría ejecutar dicha consulta usando los modelos djagno:
SELECT id, ( first+second+third ) FROM testTable
Sin agrupar. Estaba tratando de encontrar la solución utilizando google pero sin éxito.
Gracias por adelantado,
Respuestas
5 para la respuesta № 1Utilizar F() y 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"),
)