I am building Django quiz application that will contain questions of 3 types of answers:
- Single option answer;
- Multiple option answer;
- Text answer;
I am not sure how should I design django models for such pattern.
At the moment my models look like this:
class Question(CoreModel, models.Model):
TYPES = (
(1, 'radio'),
(2, 'checkbox'),
(3, 'text'),
)
type = models.CharField(max_length=8, choices=TYPES, default='radio')
text = models.CharField(max_length=2048, null=False, blank=False)
class Choice(CoreModel, models.Model):
question = models.ForeignKey(Question, on_delete=models.DO_NOTHING)
text = models.CharField(max_length=2048, null=False, blank=False)
correct = models.BooleanField(default=False)
class Answer(CoreModel, models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING)
question = models.ForeignKey(Question, on_delete=models.DO_NOTHING)
choice = models.ForeignKey(Choice, on_delete=models.DO_NOTHING)
text = models.CharField(max_length=2048, null=False, blank=False)
created = models.DateTimeField(auto_now_add=True)
But it looks like it will not work as expected. I really don't like 'choice' and 'text' fields at the same time in my Answer model but that’s all I could think of.
Any ideas or suggestions? Maybe I need some more other models for further logic?
