I have a model class which represents a user bet. I would like to calculate daily winnings for the whole database (not a single user). Winnings for each user bet is calculated with the formula odds * coins
(when result=1).
class UserBet(models.Model):
user = models.ForeignKey(User)
bet = models.ForeignKey(Bet)
coins = models.FloatField(default=0.0)
placed = models.DateTimeField(editable=False) #when user places the bet
result = models.SmallIntegerField(default=0) # 1: win, 0: no result yet, -1: lose
odds = models.FloatField(default=0.0)
week_number = models.SmallIntegerField(default=0)
year = models.SmallIntegerField(default=0)
modified = models.DateTimeField() #when result is updated
I get daily coins placed for successful results like this (MySql):
UserBet.objects.filter(result=1).extra({'date_modified':"date(modified)"}).values('date_modified').annotate(coins_sum=Sum('coins'))
however this not what I want. Coins placed by each user should get multiplied with each user-bet odds in order to get the daily winnings.
Is this possible, at all?