Re: creating formset with unknown number of unique forms

2010-04-20 Thread Tom Evans
On Tue, Apr 20, 2010 at 3:50 PM, Cody Django  wrote:
> the formset will contain an unknown series of questions.  Each
> question contains a unique prompt, integerfield for the value, and a
> choicefield with a unique list of items, based on the scope of the
> question.
>
> I would like to use a formset so I can iterate over each question in
> the template, marking up the group appropriately.
>
> is this possible to achieve with a formset?  it seems that I need to
> pass data to each individual form constructor, but this isn't possible
> using the "formset_factory" mechanism?
>

The first step of control over the formset is by providing the form
class type to be used in the formset. The formset then constructs each
form in turn, passing in any posted data or files, any supplied
initial arguments for that form, the auto_id for the form and the form
prefix.

If you need to add extra fields to the form from the fieldset context,
having created the form as described, the formset then calls
self.add_fields(form, i), where i is the numerical index of the form.
This allows you to provide any number of additional extra fields to
the form.

You can customise the behaviour of the formset by providing a
different BaseFormSet to the formset factory. See
http://docs.djangoproject.com/en/1.1/topics/forms/formsets/#adding-additional-fields-to-a-formset

Cheers

Tom

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



creating formset with unknown number of unique forms

2010-04-20 Thread Cody Django
the formset will contain an unknown series of questions.  Each
question contains a unique prompt, integerfield for the value, and a
choicefield with a unique list of items, based on the scope of the
question.

I would like to use a formset so I can iterate over each question in
the template, marking up the group appropriately.

is this possible to achieve with a formset?  it seems that I need to
pass data to each individual form constructor, but this isn't possible
using the "formset_factory" mechanism?

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