Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7692831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:56:37+00:00 2026-05-31T20:56:37+00:00

I have a web application that allows users to create an account, and in

  • 0

I have a web application that allows users to create an account, and in doing so creates a user object form a the standard Django User model, associated with a custom UserProfile model, as well as an Address model. I have built an HTML form that allows the user to update their address, and profile, by means of using a ContactInfoForm that subclasses both the AddressForm and UserProfileForm; both of which are ModelForms, as follows:

class AddressForm(forms.ModelForm):
    class Meta:
        model = common_models.Address
        exclude = ('updated_dt','address_type','created_dt')

    def __init__(self,*args,**kwargs):
        super(AddressForm,self).__init__(*args,**kwargs)

    firstname = forms.CharField(max_length=100, min_length=1, error_messages={'required':'Please Enter First Name'})
    lastname = forms.CharField(max_length=100, min_length=1, error_messages={'required':'Please Enter Last Name'})
    address1 = forms.CharField(max_length=100, min_length=1, error_messages={'required':'Please Enter Address'})
    etc...

class UserProfileForm(forms.ModelForm): 
    class Meta:
        model = common_models.UserProfile
        exclude = ('created_dt','updated_dt','entity_active','profile_hash','user','address')

    account_type = forms.ChoiceField(choices=account_choices,widget=forms.Select(attrs={'id':'account_type_list'}),error_messages={'required':'Please Select Account Type'})
    name = forms.CharField(max_length=100, min_length=1, error_messages={'required':'Please Company Name'})
    supplier_type = forms.ModelChoiceField(queryset=common_models.SupplierTypeCode.objects.all(),required=False,widget=forms.Select(attrs={'id':'account_type_select'}))
    buyer_type = forms.ModelChoiceField(queryset=common_models.ClientTypeCode.objects.all(),widget=forms.Select(attrs={'id':'account_type_select'}),required=False)


class ContactInfoForm(AddressForm,UserProfileForm): 
    class Meta:
        model = common_models.User
        exclude = ('email','username',
           'password','last_login','date_joined')

    def __init__(self,user=None,request_post_data=None,*args,**kwargs):
        if not request_post_data:
                params = dict([tuple([k,v]) for k,v in user.get_profile().address.__dict__.items()] +
            [tuple([k,v]) for k,v in user.get_profile().__dict__.items()])
                super(ContactInfoForm,self).__init__(initial=params,*args,**kwargs)
            else:
                super(ContactInfoForm,self).__init__(request_post_data,instance=user)

Now, I have the following questions:

1) How do I save the ContactInfoForm, such that both the user_profile and the address tables are updated, along with the auth_user table? I have tried overriding the save function in the ContactInfoForm, then calling the save function of Address and UserProfile as follows:

def save(self):
    address = AddressForm.save(self)
    profile = UserProfileForm.save(self)

however, that doesn’t work as the instance of self is a user object, and thus both the above functions return a user object

2) Is my implementation of the init method of the ContactInfoForm the best way to pre-populate the HTML form when the user first visits the update contact info page? In other words, is the construction of the params dictionary and using it as the initial argument correct. Keep in my mind, I have access to the user object from request.user since this view is behind a login_required decorator…

3) Is there perhaps a better way to achieve what I am trying to achieve that isn’t as complicated and more Django/Pythonic?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:56:38+00:00Added an answer on May 31, 2026 at 8:56 pm

    Usually in Django such thing is being made by creating 3 separate forms and process them all in one view.

    address_form = AddressForm(request.POST)
    profile_form = UserProfileForm(request.POST)
    contacts_form = ContactInfoForm(request.POST)
    if address_form.is_valid() and profile_form.is_valid() and contacts_form.is_valid():
        address_form.save()
        profile_form.save()
        contacts_form.save()
    

    Maybe it’s bit more code this way but it’s much more clear and easy to read.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have created a web application, using ASP.NET, that allows users to upload documents
Let say, I have a web application that allows users to upload images and
I have a web application that allows a user to search on some criteria,
In my web application I have created a form that will allow users to
I am trying create a small web application that allows a user to login
I have an idea for a web application that would allow users to create
I want to create a java application that allows users to import a web
I'm possibly developing a web-based application that allows users to create individual pages. I
I have a Java Google App Engine web application that allows user upload of
I have a bowling web application that allows pretty detailed frame-by-frame information entry. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.