From df0c02f257d96efed64586b4122d6b20a403a24d Mon Sep 17 00:00:00 2001 From: Cja Date: Thu, 30 Jan 2025 11:46:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20GetTests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/back/tests/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/back/tests/views.py b/src/back/tests/views.py index 1e8414dd3..1906a5351 100644 --- a/src/back/tests/views.py +++ b/src/back/tests/views.py @@ -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()