I am new in Django. I am working on Django 2.0. I need to show multiple 
model forms(user profile, additional details) in a single HTML form and 
save it on one click.

*form.py file is here*

class BusinessProfileForm(forms.ModelForm):
  class Meta:
    model = StUserDetails
    fields = ('user_address1', 'user_address2', 'user_city', 'user_state', 
'user_country','user_zip',)
class AdditionalDetailsForm(forms.ModelForm):
  class Meta:
    model = StUserAdditionalDetails
    fields = ('phone_number', 'fax_number', 'corporation_number', 'tax_number', 
'custom_name1','cutom_field_value1', 'custom_name2','cutom_field_value2')

*view.py*

class UserProfileView(LoginRequiredMixin, FormView):
 template_name = 'users/add_user_details.html'
 success_url = '/dashboard/'
 form_class =
   [
      BusinessProfileForm,
      AdditionalDetailsForm,
 ]

 def form_valid(self, form):
     if form.is_valid():

         profile = form.save(commit=False)
         profile.user = self.request.user
         profile.save()

         messages.add_message(self.request, messages.SUCCESS, _('Profile data 
has been successfully updated.'))

         return super(UserProfileView, self).form_valid(form) 

and HTML render is-

 <form action="POST">
 <div>{{BusinessProfileForm}}(form1) <div>
 <div>{{AdditionalDetailsForm}}(form2) <div>
  <button type="submit">Save</button>
 </form>

*Please help me I am searching on google but never able to understand.* 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b60eb146-9376-4817-8da6-24e30b81a47e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to