Monday 15 July 2013

django - Setting choices for a field in a Form Wizard? -


I'm trying to create a simple quiz application. I am trying to use the form wizard, but I do not see anything in Docs about setting options for a form field. I would like to use the same form field multiple times

models.py
  class options (models.model): choice = model. Kharefild (max_long = 64) def __unicode __ (self): Returns self.choice #create A multi-choice quiz for starting class questions (models.Model): Question = Model. CHAfild (max_long = 64) answer = model. Kharifield (max_long = 64) option = model. Multi-standard Field (Choice) module = Model.Carfield (max_length = 64) def __unicode __ (self): return self. Question Category Quiz (models.Model): name = models.CharField (max_length = 64) Question = models.ManyToManyField (question) def __unicode __ (self): return self.name   

views .py
  class quiz (session wizard view): DEF (self, form_list, ** quad): Return Render_to_propx ('done.html', {'Form_data': [form_cleaned_data form_list in form For example],}   

urls.py
  url (r '^ answer / (? P & lt; question_ id & gt; \ d + ), 'Quiz.views.answer_question', name = 'answer_question'),    

Comes for option Its the same concept for form fields as model zones. For model areas.

Unless you plan to add many options, you should not have just one table for it You can change your model:

  CHOICES = ( (1, 'one'), (2, 'two')) class (models.Model): option = model.tector field (option if you make it like above, then a  ModelForm  This will do what you expect and provide a drop down with the right options for the 

No comments:

Post a Comment