How get the weighted average from queryset as quickly as possible. Is it possible without the use of loops. Below is an example.
My models.py:
class Product(models.Model):
price = models.DecimalField(max_digits=15, decimal_places=2)
weighted = models.IntegerField()
day = models.IntegrField()
In my database, I have the following values ββfor day 1:
Object ID I: Price=100, weighted=12, day=1
Object ID II: Price=50, weighted=1, day=1
Object ID III: Price=75, weighted=3, day=1
how to calculate the weighted average for day one?
day_1_average_weighted = Product.objects.filter(day=1) ???how to get a weighted average - 71.88???