-import re
+import re, json
from django.db import models
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator
Incorrect_questions is a list in the same format.
Sitting deleted when quiz finished unless quiz.exam_paper is true.
+
+ User_answers is a json object in which the question PK is stored
+ with the answer the user gave.
"""
user = models.ForeignKey('auth.User')
complete = models.BooleanField(default=False, blank=False)
- user_answers = models.TextField(blank=True)
+ user_answers = models.TextField(blank=True, default='{}')
objects = SittingManager()
return self.quiz.fail_text
def add_user_answer(self, question, guess):
- pass
+ current = json.loads(self.user_answers)
+ current[question.id] = guess
+ self.user_answers = json.dumps(current)
class Question(models.Model):
self.sitting.mark_quiz_complete()
self.assertEqual(self.sitting.complete, True)
- def test_user_answers(self):
+ def test_add_user_answer(self):
self.answer1 = Answer.objects.create(id=123,
question=self.question1,
content='bing',