Use 2 separate ModelForms. One for each model. If the 2 models happen
to have overlapping field names, you can use the 'prefix' argument to
the form to avoid name collisions.
One bit to be wary of is calling form.is_valid() in your view. If you
have something like this:
if user_form.is_valid() and profile_form.is_valid():
# save stuff
and user_form.is_valid is False, profile_form.is_valid() won't be
called. I usually write a function called all_valid(list_of_forms)
that calls is_valid() on each form and returns False if any of them
fail.
Joseph
No. Formsets are designed to work with instances of a single model
type. Inline formsets are closer to what you want, but really, that
adds a lot more complication that just writing 2 forms would. Even if
you *do* use an inline formset, you're still going to have to render
both the form and the formset.
> My solution is to create a class that generalizes working with
> multiple model forms. Or rather, it abstract the multiple form
> handling and printing behind a Form interface so that the view and
> template don't know the difference. It'd be nice to make more use of
> formsets or provided code since I feel like I've reinvented the wheel.
You aren't reinventing the wheel. There isn't code in Django to do
what you're trying to do. If you really feel like you need to write
some sort of wrapper for this, I'd suggest keeping the case you deal
with down to a simple situation: 1 child object with a OneToOneField
or a ForeignKey to a parent object.
Joseph