[Answer]-Django queryset aggregate multiple operations fields

1👍

See the Django docs on aggregation for detail but 1. should be something like:

from django.db.models import Sum

DdtsArticoli.objects.all().aggregate(
    your_key=Sum(F('quantita') * F('prezzo'), output_field=FloatField()))

Number 2. is no aggragation, you can simply calculate it:

(obj.quantita * obj.prezzo) / (1 + (obj.ddt.fattura.iva/100.0))

Where obj is your object aka. your database row.

Number 3. should be trivial then.

Leave a comment