Re: One from from multiple models using ModelForm
On Dec 4, 6:05 pm, CrabbyPete <pete.do...@gmail.com> wrote:
> I wanted to combine two models into one form so I created the
> following
>
> class UserForm( ModelForm ):
> class Meta:
> model = User
> fields = ('email','first_name','last_name')
>
> class ProfileForm( ModelForm ):
> class Meta:
> model = Profile
>
> class UserProfile ( UserForm, ProfileForm )
> class Meta( UserForm.Meta, ProfileForm.Meta)
> exclude = ('user',)
>
> It only inherits UserForm
>
> Is there a way to create one form using 2 modelform or to have
> ProfileForm inherit from UserForm and add
> Profile form data. Something like this
I don't think that is possible.
You will need to use both forms separately, and if you need combined
validation or something like that, then do that in your view code. You
can create a wrapper class which behaves mostly like a form, but
delegates the actions to the two underlying forms. (eg is_valid():
return form1.is_valid() and form2.is_valid()). Making it behave
exactly like a single form will be hard.
- Anssi
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home