问题
I'm trying to customise this django quiz app
I want that it can be possible to add images for every question and every answer. But some will not have any images, either answers. What is the best way to do this?
This is the actual model:
class Question(models.Model):
quiz = models.ManyToManyField(Quiz, blank=True, )
category = models.ForeignKey(Category, blank=True, null=True, )
content = models.CharField(max_length=1000,
blank=False,
help_text="Enter the question text that you want displayed",
verbose_name='Question',
)
explanation = models.TextField(max_length=2000,
blank=True,
help_text="Explanation to be shown after the question has been answered.",
verbose_name='Explanation',
)
class Meta:
verbose_name = "Question"
verbose_name_plural = "Questions"
ordering = ['category']
def __unicode__(self):
return self.content
class Answer(models.Model):
question = models.ForeignKey(Question)
content = models.CharField(max_length=1000,
blank=False,
help_text="Enter the answer text that you want displayed",
)
correct = models.BooleanField(blank=False,
default=False,
help_text="Is this a correct answer?"
)
def __unicode__(self):
return self.content
回答1:
Create new model with
- image,
- type - answer or question
- answer_id or question_id
Then you can add to answer/question as many images as you wish.
来源:https://stackoverflow.com/questions/24346983/images-in-quiz-model