This commit is contained in:
2024-12-11 23:22:09 +01:00
parent 4b86b33872
commit 9b7944c14d
53 changed files with 2054 additions and 249 deletions

View File

@@ -0,0 +1,14 @@
from quiz.models import Quiz
class QuizConverter:
regex = r"\d+"
def to_python(self, value: str) -> Quiz:
try:
return Quiz.objects.get(id=value)
except Quiz.DoesNotExist:
raise ValueError
def to_url(self, value: Quiz | int) -> str:
return str(value.id) if isinstance(value, Quiz) else value