テストの試行回数を test_id でグループ化し、各テストの平均を取得する Django クエリがあります。
test_attempts テーブルには、特定のテストでユーザーが行った各テストの試行が記録されます。テストごとの平均試行回数を知りたい
これが私のクエリです:
average = TestAttempts.objects.values('test_id').annotate(Avg(Count('test_id'))).filter(user_id=id)
次のエラーが表示されます: 'Count' オブジェクトには属性 'split' がありません
生の SQL を書かずにこれを処理する方法はありますか?
更新: ここに TestAtttemt モデルがあります
class TestAttempts(models.Model):
id = models.IntegerField(primary_key=True)
user_id = models.IntegerField()
test_id = models.IntegerField()
test_grade = models.DecimalField(max_digits=6, decimal_places=1)
grade_date_time = models.DateTimeField()
start_time = models.DateTimeField()
seconds_taken = models.IntegerField()
taking_for_ce_credit = models.IntegerField()
ip_address = models.CharField(max_length=25L)
grade_points = models.DecimalField(null=True, max_digits=4, decimal_places=1, blank=True)
passing_percentage = models.IntegerField(null=True, blank=True)
passed = models.IntegerField()
class Meta:
db_table = 'test_attempts'