I have three models, Contender, Week and Vote, each contender can have votes based on week,
class Contender(models.Model)
week = models.ManyToManyField(Week)
class Week(models.Model):
date_start = models.DateField()
class Vote(models.Model):
contender = models.ForeignKey(Contender)
week = models.ForeignKey(Week)
I would like to add something to the Contender, so I did this:
c = Count('vote', vote__week__date_start = "2011-01-03")
contenders = Contender.objects.all().annotate(vote_count=c).order_by('-vote_count')
contenders[0].vote_count
the problem is that when I add a vote with another Week (that has diferent date_start) the .vote_count value is changes and thus it seems like the extra parameters I pass to the Count object does not matter.
How do I do this type of annotation in the Django ORM?