Images in quiz model

。_饼干妹妹 提交于 2020-01-05 04:08:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!