Handling multiple Survey questions
We have the display of a single question form working, what's left to do? First, we need to handle the display of however many questions that are associated with a survey, instead of just a single question. Second, we need to handle receiving, validating, and processing the results. We'll focus on the first task in this section.
Creating the data for multiple questions
Before writing the code to handle multiple questions, let's add another question to our test survey so that we'll be able to see the new code work. The upcoming examples will display this additional question:
Coding support for multiple questions
Next, change the view to create a list of QuestionVoteForms
and pass this list in the template context:
def display_active_survey(request, survey): qforms = [] for i, q in enumerate(survey.question_set.all()): if q.answer_set.count() > 1: qforms.append(QuestionVoteForm(q, prefix=i)) return render_to_response('survey...