I am using Django ORM to query a database called Product having column name price(Decimal) and stock_units(int). I want to Multiply both of the columns and get the accumulated summation.
report = Product.objects.filter(stock_units__gte=1).aggregate(Count('name'), Sum('stock_units'), Sum(F('price')*F('stock_units')))
I expect the output to be {
"Total product Sold ": {
"name__count": 2,
"stock_units__sum": 844,
"Total amount": 84400
}
}
But it through an error:
TypeError: 'F' object is not subscriptable