{'item__sale_code': None, 'order__customer__code': 'CLC', 'outstanding_quantity': '5.00', 'order__currency__name': 'YEN', 'original_amount': '92500.00', 'order__customer__name': 'Cloud Customer', 'local_amount': Decimal('0')}
{'item__sale_code': 'None', 'order__customer__code': 'CLC', 'outstanding_quantity': '3.00', 'order__currency__name': 'YEN', 'original_amount': '36000.00', 'order__customer__name': 'Cloud Customer', 'local_amount': Decimal('0')}
{'item__sale_code': 'None', 'order__customer__code': 'SGC', 'outstanding_quantity': '10.00', 'order__currency__name': 'YEN', 'original_amount': '66000.00', 'order__customer__name': 'SCG Customer', 'local_amount': Decimal('0')}
我在django中有一个元组列表。现在,我想将具有相同Customer的两行分组到一行,并计算outstanding_quantity
和original_amount
的总和。它应该是这样的:
{'item__sale_code': 'None', 'order__customer__code': 'CLC', 'outstanding_quantity': '8.00', 'order__currency__name': 'YEN', 'original_amount': '128500.00', 'order__customer__name': 'Cloud Customer', 'local_amount': Decimal('0')}
{'item__sale_code': 'None', 'order__customer__code': 'SGC', 'outstanding_quantity': '10.00', 'order__currency__name': 'YEN', 'original_amount': '66000.00', 'order__customer__name': 'SCG Customer', 'local_amount': Decimal('0')}
这是我的代码python.py:
my_list = my.values('order__customer__code', 'order__customer__name', 'order__currency__name',
'item__sale_code') \
.annotate(Sum('outstanding_quantity')) \
.annotate(Sum('original_amount'))