I’m trying to write a form for a basic multiple choice quiz. I’ve tried writing the form manually on my template and it’s fine but I would like to use a django form instead. I’m trying to assign the options for the form on my template but I can’t seem to find the correct way of doing this anywhere so I’d appreciate some help
What you are looking for is a ChoiceField for your questions. You can then define a function to return the set of choices to be used for each question.
Also, since you are rendering multiple instances of essentials the same form, you want to build this page using a formset.
(Side note - I’m hoping this is a copy/paste error, but these lines:
don’t show up as being indented in your view. If they’re not indented as part of your view, that is a mistake.)
The purpose of the formset is to allow the formset to generate the individual forms, including the construction of any specialization that may be necessary.
In the section for QuizForm, I would recommend changing one of these variables named “options” to something else, just to avoid confusion. (Your “You in six months” will appreciate it.)
For actually creating “dynamic options” for forms, I suggest you read: