2👍
✅
Your query does not get returns a numeric value, but a dictionary:
context["sales"] = self.get_queryset().aggregate(Sum('sales'))
#{'sales__sum': Decimal('123123')}
context["net_profit"] = self.get_queryset().aggregate(Sum('net_profit'))
#{'net_profit__sum': Decimal('123123')}
You should filter catching the dictionary value:
result = context['sales']['sales__sum'] / context['net_profit']['net_profit__sum']
3👍
If like this:
sales = context['sales']
net_profit = context['net_profit']
the sales and the net_profit are the object.
So, the html show net margin is {{ sales.sale__sum/ net_profit.net_profit__sum }}
The django template can use the cal of numbers.
Source:stackexchange.com