On Mon, 2009-08-03 at 20:29 -0700, sico wrote:
> Hi,
> 
> Just to clarify here, I really want to keep using forms.ModelForm to
> avoid having to redefine any data types and labels.  I could create a
> single form that has all the fields I want and use that in a formset.
> But then I have to duplicate the field/model definitions and also
> handle the binding of the data from the form to the model.

Firstly, you don't necessarily need a formset here. You can use multiple
Django Form subclass objects in a single HTML form. So you can create
you sequence of ModelForms and pass them into your template and render
them all however you like. Then validate them each in turn and if
is_valid() passes, you're set to go.

Alternatively, you can create a BaseFormSet subclass and override the
_construct_form() method to produce each of your model forms in turn
(the index "i" that is passed in is the form number in the formset).
That's a small variation on the technique I use in [1], except you're no
longer using formset_factory() or modelformset_factory(), as you want a
fairly different form instance returned for each call to
_construct_form().

There *might* be some curly bits to work around with respect to
populating the data correctly in such a customised formset, so be
prepared to experiment a bit and read the source.

[1]
http://www.pointy-stick.com/blog/2009/01/23/advanced-formset-usage-django/

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to