我正在尝试制作一个简单的测验应用程序。我正在尝试使用表单向导,但我在文档中没有看到任何关于设置表单字段选择的内容。我也想多次使用同一个表单域。
模型.py
class Choice(models.Model):
choice = models.CharField(max_length=64)
def __unicode__(self):
return self.choice
#create a multiple choice quiz to start
class Question(models.Model):
question = models.CharField(max_length=64)
answer = models.CharField(max_length=64)
choices = models.ManyToManyField(Choice)
module = models.CharField(max_length=64)
def __unicode__(self):
return self.question
class Quiz(models.Model):
name = models.CharField(max_length=64)
questions = models.ManyToManyField(Question)
def __unicode__(self):
return self.name
视图.py
class QuizWizard(SessionWizardView):
def done(self, form_list, **kwargs):
return render_to_response('done.html', {
'form_data':[form.cleaned_data for form in form_list],
})
网址.py
url(r'^answer/(?P<question_id>\d+)', 'quiz.views.answer_question', name='answer_question'),