测验模型中的图像

时间:2014-06-22 00:07:47

标签: python django django-models django-admin

我尝试自定义this django quiz app

我希望能够为每个问题和每个答案添加图像。但有些人不会有任何图像,无论是答案。这样做的最佳方式是什么?

这是实际模型:

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 个答案:

答案 0 :(得分:2)

使用

创建新模型
  • 图片,
  • 类型 - 回答或问题
  • answer_id或question_id

然后您可以根据需要添加回答/问题尽可能多的图像。