mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-03-06 04:44:19 +01:00
More!
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from django.db import models
|
||||
from django.db.models import QuerySet
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_stubs_ext.db.models import TypedModelMeta
|
||||
|
||||
from quiz.models import Answer
|
||||
|
||||
|
||||
class NoActiveTestForSeason(Exception):
|
||||
pass
|
||||
@@ -21,6 +24,33 @@ class Question(models.Model):
|
||||
)
|
||||
enabled = models.BooleanField(default=True, verbose_name=_("enabled"))
|
||||
|
||||
@property
|
||||
def order(self):
|
||||
return self._order
|
||||
|
||||
@property
|
||||
def right_answer(self) -> QuerySet[Answer]:
|
||||
return self.answers.filter(is_right_answer=True)
|
||||
|
||||
@property
|
||||
def has_right_answer(self) -> bool:
|
||||
return self.answers.filter(is_right_answer=True).count() > 0
|
||||
|
||||
@property
|
||||
def errors(self) -> str | None:
|
||||
if self.answers.count() == 0:
|
||||
return _("Error: Question has no answers")
|
||||
|
||||
n_correct_answers = self.answers.filter(is_right_answer=True).count()
|
||||
|
||||
if n_correct_answers == 0:
|
||||
return _("Error: This question has no right answer!")
|
||||
|
||||
if n_correct_answers > 1:
|
||||
return _("Warning: This question has multiple correct answers")
|
||||
|
||||
return None
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self._order + 1}. {self.question} ({self.quiz}) ({self.answers.count()} answers, {self.answers.filter(is_right_answer=True).count()} correct)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user