Python django计数具有相同相关记录的记录数

Python django计数具有相同相关记录的记录数,python,django,orm,annotations,Python,Django,Orm,Annotations,我正在使用django 1.5.5和Mysql 我有这个模型 class Student(models.Model): username = models.CharField(max_length=200,unique = True) class Score(models.Model) student = models.ForeignKey(Student) date = models.DateTimeField() score = models.Int

我正在使用django 1.5.5和Mysql

我有这个模型

class Student(models.Model):
     username = models.CharField(max_length=200,unique = True)

class Score(models.Model)
     student = models.ForeignKey(Student)
     date = models.DateTimeField()
     score = models.IntegerField()
我想得到所有分数记录,这些记录的分数为0,同一个学生的分数为0

我所尝试的:

scores = Score.objects.annotate(score_count = Count('student__id')).filter(score = 0 , score_count__gt = 1)
我试过的另一件事,我想这件事确实能满足我的需要,但它需要两个查询

students = Score.objects.filter(score = 0).values('student__id').annotate(c=Count('student__id')).filter(c__gt=1).values_list('student__id',flat=True)
score = Score.objects.filter(score = 0 , student__id__in = students)
有什么方法可以在一个查询中完成吗

no_of_records = len(Score.objects.values('student__id').filter(score=0).annotate(c=Count('score')‌​).f‌​ilter(c__gt=1)) 


Score.objects.values('student_uid')。filter(Score=0)。annotation(c=Count('Score'))。filter(c_ugt=1)
??@AamirAdnan这只会给我值,而不会给我分数记录。
no_of_records = len(Score.objects.values('student__id').filter(score=0).annotate(c=Count('score')‌​).f‌​ilter(c__gt=1)).count()