This commit is contained in:
Ross
2021-12-15 18:34:40 +00:00
parent 837aab5384
commit 4fa85f79ef
+14 -4
View File
@@ -425,6 +425,10 @@ class CidUserAnswer(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
score = models.CharField(
max_length=1, choices=Answer.MarkOptions.choices, default=Answer.MarkOptions.UNMARKED
)
def __str__(self):
try:
exam = self.exam
@@ -456,10 +460,16 @@ class CidUserAnswer(models.Model):
# s = s.translate(str.maketrans('', '', string.punctuation))
# return s
def get_answer_score(self):
q = self.question
ans = self.answer_compare
marked_ans = q.answers.filter(answer_compare__iexact=ans).first()
def get_answer_score(self, cached=True):
if cached and self.score:
marked_ans = self.score
else:
q = self.question
ans = self.answer_compare
marked_ans = q.answers.filter(answer_compare__iexact=ans).first()
self.score = marked_ans
self.save()
mark = "unmarked"
if marked_ans is not None: