изменение в TestResultCreate

This commit is contained in:
Cja committed 2025-01-31 12:25:44 +03:00
1 parent 416af53d90
commit 73e827669e
1 file changed
+4 -2
+4 -2
View File
@@ -144,7 +144,7 @@ class TestResultCreate(generics.ListCreateAPIView):
serializer.save(attempt=test_attempt) serializer.save(attempt=test_attempt)
self.update_testing(user, test_info) self.update_testing(user, test_info)
return Response(test_info['is_passed']) return Response(data={'score': test_info['score'], 'answered_questions_total': test_info['answered_questions_total']})
def create_test_attempt(self, user, test_info): def create_test_attempt(self, user, test_info):
test = test_info['test'] test = test_info['test']
@@ -163,6 +163,7 @@ class TestResultCreate(generics.ListCreateAPIView):
answer_ids = [item['answer'] for item in request.data] answer_ids = [item['answer'] for item in request.data]
test_answers = TestAnswer.objects.filter(id__in=answer_ids) test_answers = TestAnswer.objects.filter(id__in=answer_ids)
test = test_answers[0].question.test test = test_answers[0].question.test
answered_questions_total = test_answers.values('question').distinct().count()
correct_questions = sum( correct_questions = sum(
TestAnswer.objects.filter( TestAnswer.objects.filter(
@@ -179,7 +180,8 @@ class TestResultCreate(generics.ListCreateAPIView):
result = { result = {
"is_passed": correct_questions >= pass_perc, "is_passed": correct_questions >= pass_perc,
"score": correct_questions, "score": correct_questions,
"test": test "test": test,
"answered_questions_total": answered_questions_total,
} }
return result return result