On Fri, Oct 29, 2010 at 11:58 AM, Bill Brigham <[email protected]> wrote:

> On a questionnaire, you have one or more questions which will require
> either an essay answer or multiple choice answers. When creating a new
> questionnaire, I would like to show a textarea for the Question.text
> common to both types, a radio select for the Question.question_type,
> and then present either the EssayQuestion.initial_answer textarea or
> the inputs for adding multiple choice options. The user can click "add
> question" to append another form beneath to enter a new question. It's
> only on the final "save questionnaire" that I handle the POST and
> save.

First, let me say that I'm still learning Django myself, and don't
understand formsets especially well. There might be an easy and/or
elegant way to handle this with formsets that I don't know.

That said, if you are only entering new questions one by one, it sure
sounds easier to me to POST and save each new question individually.
If there aren't many questions per questionaire, it probably wouldn't
hurt to post/refresh the whole page each question. If there are a lot
of questions, you could use javascript to make the building process
smoother for the user.

> I have spent a few days now trying different permutations of
> formsets, modelformsets and inline_formsets but to no avail. The
> closest I've got is to create a QuestionFormset, EssayQuestionFormset
> and a MultipleChoiceQuestionFormset, then keep track of which form
> belongs to which question when saving. I'm not sure how to reconstruct
> the forms should it raise validation errors though.
>
> Another option is to create a QuestionForm containing fields for 0..N
> possible fields, i.e. multiplechoice_choice_0,
> multiplechoice_correct_0, multiplechoice_choice_1,... But this feels
> wrong to me.

Me too.

> It seems overly complicated which makes me think I'm going about it
> the wrong way. Any help would be much appreciated please!

If you can do it, handling one question at a time will be easier. And
it will be easier to maintain when you have to add a new question type
of checkbox, dropdown list, or whatever it is they'll want next.  :)

Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to