изменение в TestResultCreate
This commit is contained in:
1 parent
416af53d90
commit
73e827669e
1 file changed
+4
-2
@@ -144,7 +144,7 @@ class TestResultCreate(generics.ListCreateAPIView):
|
||||
serializer.save(attempt=test_attempt)
|
||||
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):
|
||||
test = test_info['test']
|
||||
@@ -163,6 +163,7 @@ class TestResultCreate(generics.ListCreateAPIView):
|
||||
answer_ids = [item['answer'] for item in request.data]
|
||||
test_answers = TestAnswer.objects.filter(id__in=answer_ids)
|
||||
test = test_answers[0].question.test
|
||||
answered_questions_total = test_answers.values('question').distinct().count()
|
||||
|
||||
correct_questions = sum(
|
||||
TestAnswer.objects.filter(
|
||||
@@ -179,7 +180,8 @@ class TestResultCreate(generics.ListCreateAPIView):
|
||||
result = {
|
||||
"is_passed": correct_questions >= pass_perc,
|
||||
"score": correct_questions,
|
||||
"test": test
|
||||
"test": test,
|
||||
"answered_questions_total": answered_questions_total,
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
Reference in new issue
Block a user