[Answered ]-Reduce queries to the same Django model when using Model.objects.all()

2👍

You can do this all in one query:

traffic = Traffic.objects.all().aggregate(Sum('sessions'),
                                          Sum('new_users'),
                                          ...)
traffic_sessions = traffic.get('sessions_sum')
...

Leave a comment