Aggregation
from django.db.models import Sum
from myapp.models import Order
# Calculate the total price of all orders
total_price = Order.objects.aggregate(total_price=Sum('total_price'))
print(total_price)Last updated
from django.db.models import Sum
from myapp.models import Order
# Calculate the total price of all orders
total_price = Order.objects.aggregate(total_price=Sum('total_price'))
print(total_price)Last updated