totals = {
'qty': 0,
'total_amount': 0,
'cost': 0,
'profit': 0,
}
for order in orders:
totals['qty'] += order.qty
totals['total_amount'] += order.total_amount
totals['cost'] += order.cost
totals['profit'] += order.profit
totals = defaultdict(int)
for order in orders:
for k in ['qty', 'total_amount', 'cost', 'profit']:
totals[k] += getattr(order, k)