изменение в GetTests

This commit is contained in:
Cja committed 2025-01-30 11:46:16 +03:00
1 parent 0c568f796f
commit df0c02f257
1 file changed
+5 -1
+5 -1
View File
@@ -55,8 +55,12 @@ class GetTests(generics.ListAPIView):
return status_filters.get(status, Test.objects.none()).order_by('dateend')
def set_attemps_number(self, user, tests):
test_ids = [test.id for test in tests]
attempt_counts = TestAttempt.objects.filter(user=user, test__id__in=test_ids).values('test').annotate(count=Count('test'))
attempt_counts = {item['test']: item['count'] for item in attempt_counts}
for test in tests:
test.attemps_number = get_attempt_count(user=user, test=test)
test.attemps_number = test.attemps_number - attempt_counts.get(test.id, 0)
class TestDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Test.objects.all()