Doug, That's awesome, thanks. It's a shame that it requires an extra database hit after the POST, but that's still infinitely neater than my suggestion.
Can you clarify for me what the return statement in form_builder is doing? I'm new to python, but I thought type() was used to determine the datatype of an object. Thanks again, Matt. On Aug 20, 11:53 pm, Doug B <[EMAIL PROTECTED]> wrote: > You could build a builder function that does what you want (totally > untested, rough example). The form_for_model functions are good > working examples if I screwed something up here. > > def form_builder(question_instance): > base_fields={'text': forms.CharField(widget=forms.Textarea, > help_text=question_instance.exampleAnswer, > verbose_name=question_instance.questionText) } > return type('QAForm', (forms.BaseForm), {'base_fields': > base_fields}) > > def form_set_builder(question_set,postdata=None): > form_set=[] > valid=True > for q in question_set: > Form=form_builder(q) > # will use question pk id as prefix to differentiate the forms > from one another > if postdata: # bound form if request.POST passed in as postdata > form=Form(postdata,prefix=q._get_pk_val()) > valid=form.is_valid() > else: # unbound form > form=Form(prefix=q._get_pk_val()) > form_set.append(form) > return form_set, valid > > def view(request): > qs = Question.objects.... > if request.POST: > form_set,valid=form_set_builder(qs,request.POST) > if valid: > #loop through and save > .... > else: > return with errors > else: > form_set,throwaway=form_set_builder(qs) > .... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---