Модели class results_stat models Model book models ForeignKey Books ov

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#Модели
class results_stat(models.Model):
book = models.ForeignKey(Books)
overall = models.IntegerField()
class Books(models.Model):
book_id = models.IntegerField(primary_key=True, verbose_name = "Код")
book_name = models.CharField(max_length=255, verbose_name = "Название")
def __unicode__(self):
return self.book_name
# Запрос
stat = results_stat.objects.filter(r_filter).\
annotate(\
overall = Sum('overall')).\
values_list('book', 'overall').\
select_related('book')