You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
66 lines
2.0 KiB
from django.db import models
|
|
from django.utils.translation import gettext_lazy as _
|
|
from apps.account.models import User
|
|
|
|
|
|
|
|
class Quiz(models.Model):
|
|
lesson = models.ForeignKey("course.CourseLesson", verbose_name=_('lesson'), related_name='quizzes', on_delete=models.CASCADE)
|
|
|
|
title = models.CharField(max_length=255, verbose_name=_('title'), help_text="Quiz Title")
|
|
description = models.CharField(max_length=55, blank=True, null=True, verbose_name="Description")
|
|
each_question_timing = models.PositiveIntegerField()
|
|
status = models.BooleanField(default=True)
|
|
|
|
|
|
class Meta:
|
|
verbose_name = "Quiz"
|
|
verbose_name_plural = "Quizzes"
|
|
ordering = ("-id",)
|
|
|
|
def __str__(self):
|
|
return f"Quiz: {self.id}"
|
|
|
|
def __repr__(self):
|
|
return f"Quiz(id={self.id})"
|
|
|
|
|
|
|
|
|
|
class Question(models.Model):
|
|
CHOICES = [
|
|
(1, 'Option 1'),
|
|
(2, 'Option 2'),
|
|
(3, 'Option 3'),
|
|
(4, 'Option 4'),
|
|
]
|
|
|
|
quiz = models.ForeignKey(Quiz, verbose_name='quiz', on_delete=models.CASCADE, related_name='questions')
|
|
question = models.CharField(max_length=255)
|
|
option1 = models.CharField(max_length=255, verbose_name='option 1')
|
|
option2 = models.CharField(max_length=255, verbose_name='option 2')
|
|
option3 = models.CharField(max_length=255, verbose_name='option 3')
|
|
option4 = models.CharField(max_length=255, verbose_name='option 4')
|
|
correct_answer = models.PositiveSmallIntegerField(choices=CHOICES)
|
|
created_at = models.DateTimeField(auto_now_add=True, verbose_name='created at')
|
|
priority = models.IntegerField(null=True, blank=True)
|
|
|
|
|
|
class Meta:
|
|
verbose_name = "Question"
|
|
verbose_name_plural = "Questions"
|
|
ordering = ("-priority", "-id",)
|
|
|
|
def __str__(self):
|
|
return self.question
|
|
|
|
def __repr__(self):
|
|
return f"Question(id={self.id})"
|
|
|
|
|
|
class QuizRankUser(User):
|
|
class Meta:
|
|
proxy = True
|
|
verbose_name = 'Rank Quiz'
|
|
verbose_name_plural = 'Rank Quizzes'
|
|
|