django: time range based aggregate query
I have the following models, Art and ArtScore: class Art(models.Model): title = models.CharField() class ArtScore(models.Model): art = models.ForeignKey(Art) date = models.DateField(auto_now_add = True) amount = models.IntegerField() Certain user actions results in an ArtScore entry, for instance whenever you click 'I like this art', I save a certain amount of ArtScore for that Art. Now I'm trying to show a page for 'most popular this week', so I need a query aggregating only ArtScore amounts for that time range. I built the below query but it's flawed... popular = Art.objects.filter( artscore