diff --git a/src/back/tests/views.py b/src/back/tests/views.py index e996c8b99..a0a94d9f8 100644 --- a/src/back/tests/views.py +++ b/src/back/tests/views.py @@ -517,6 +517,10 @@ class TestResultView(generics.ListCreateAPIView): test_answers = TestAnswer.objects.filter(id__in=answer_ids) test = Test.objects.get(id=test_id) answered_questions_total = test_answers.values('question').distinct().count() + q_count = test.question_count + all_questions = len(TestQuestion.objects.filter(test=test)) + if all_questions <= q_count: + q_count = all_questions correct_questions = sum( TestAnswer.objects.filter( @@ -531,8 +535,10 @@ class TestResultView(generics.ListCreateAPIView): pass_perc = test.pass_perc correct_answers_perc = 0 - if answered_questions_total !=0: - correct_answers_perc = correct_questions/answered_questions_total*100 + if q_count !=0: + correct_answers_perc = correct_questions/q_count*100 + # if answered_questions_total !=0: + # correct_answers_perc = correct_questions/answered_questions_total*100 result = { "is_passed": correct_answers_perc >= pass_perc, "score": correct_questions,