I need to extract some products from orders with the same SKU number.
orders=Order.objects.filter(products__contains=[{"sku":"002-2-1"}])
for e in orders:
print(e.products)
>>> [{'sku': 002-2-1, 'price': '366.00'}, {'sku': 002-2-1, 'price': '300.00'}] # 2 products in 1 order
>>> [{'sku': 002-2-1, 'price': '400.00'}] # 1 product in the order
I need to find the mean value of "price"
I tried to get a one list with dicts:
a = sum(list(orders.values_list("products", flat=True)), [])
[{'sku': 002-2-1, 'price': '366.00'}, {'sku': 002-2-1, 'price': '300.00'}, {'sku': 002-2-1, 'price': '400.00'}]
How can I find the mean value of price?
[mean(e.get("price")) for e in a]
May be there is a better way to find it via F?