class ResultStat models Model book models ForeignKey Book overall mode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class ResultStat(models.Model):
book = models.ForeignKey(Book)
overall = models.IntegerField()
class Book(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.book_name
ResultStat.objects.select_related().\
filter(...).\
annotate(overall=Sum('overall')).\
values('book__name', 'overall')