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

  • SEARCH
  • Home
  • 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 6591937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:29:24+00:00 2026-05-25T17:29:24+00:00

Am trying to create a registration form by extending django-registration app and using Django

  • 0

Am trying to create a registration form by extending django-registration app and using Django Profile. I have created the model and form for the profile and when I checked through the django shell it is generating the fields. For the profile fields i am using ModelForm. Now I am struck on how to bring both the django-registration and the profile fields together. Following are the code i have developed

model.py

class UserProfile(models.Model):
    """
    This class would define the extra fields that is required for a user who will be registring to the site. This model will
    be used for the Django Profile Application
    """
    GENDER_CHOICES = ( 
        ('M', 'Male'),
        ('F', 'Female'),
    )

    #Links to the user model and will have one to one relationship
    user = models.OneToOneField(User)    

    #Other fields thats required for the registration
    first_name = models.CharField(_('First Name'), max_length = 50, null = False)    
    last_field = models.CharField(_('Last Name'),max_length = 50)
    gender = models.CharField(_('Gender'), max_length = 1, choices=GENDER_CHOICES, null = False)    
    dob = models.DateField(_('Date of Birth'), null = False)    
    country = models.OneToOneField(Country)
    user_type = models.OneToOneField(UserType)
    address1 = models.CharField(_('Street Address Line 1'), max_length = 250, null = False)
    address2 = models.CharField(_('Street Address Line 2'), max_length = 250)
    city = models.CharField(_('City'), max_length = 100, null = False)
    state = models.CharField(_('State/Province'), max_length = 250, null = False)
    pincode = models.CharField(_('Pincode'), max_length = 15)
    created_on = models.DateTimeField()
    updated_on = models.DateTimeField(auto_now=True)

forms.py

class UserRegistrationForm(RegistrationForm, ModelForm):

    #resolves the metaclass conflict
    __metaclass__ = classmaker()

    class Meta:
        model = UserProfile
        fields = ('first_name', 'last_field', 'gender', 'dob', 'country', 'user_type', 'address1', 'address2', 'city', 'state', 'pincode')

Now what should i do to mix django-registration app with my custom app. I had gone through lots of sites and links to figure it out including Django-Registration & Django-Profile, using your own custom form but i am not sure to move forward especially since i am using ModelForm instead.

UPDATE (26th Sept, 2011)

I made the changes as suggested by @VascoP below. I updated template file and then from my view.py i created the following code

def register(request):
    if request.method == 'POST':        
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            UserRegistrationForm.save()
    else:
        form = UserRegistrationForm()
    return render_to_response('registration/registration_form.html',{'form' : form}, context_instance=RequestContext(request))

After the following change the form is correctly getting rendered but the problem is that the data is not getting saved. Please help me.

UPDATE (27th Sept, 2011)

UserRegistrationForm.save() was changed to form.save(). The updated code is for views.py is as follows

def register(request):
    if request.method == 'POST':        
        form = UserRegistrationForm(request.POST)
        if form.is_valid():
            form.save()
    else:
        form = UserRegistrationForm()
    return render_to_response('registration/registration_form.html',{'form' : form}, context_instance=RequestContext(request))

Even after the update the user is not getting saved. Instead I am getting an error

‘super’ object has no attribute ‘save’

I can see that there is no save method in RegistrationForm class. So what should i do now to save the data? Please help

  • 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-25T17:29:25+00:00Added an answer on May 25, 2026 at 5:29 pm

    You are aware that the User model already has first_name and last_name fields, right? Also, you misstyped last_name to last_field.

    I would advise to extend the form provided by django-registration and making a new form that adds your new fields. You can also save the first name and last name directly to the User model.

    #get the form from django-registration
    from registration.forms import RegistrationForm
    
    class MyRegistrationForm(RegistrationForm):
        first_name = models.CharField(max_length = 50, label=u'First Name')    
        last_field = models.CharField(max_length = 50, label=u'Last Name')
        ...
        pincode = models.CharField(max_length = 15, label=u'Pincode')
    
    
        def save(self, *args, **kwargs):
            new_user = super(MyRegistrationForm, self).save(*args, **kwargs)
    
            #put them on the User model instead of the profile and save the user
            new_user.first_name = self.cleaned_data['first_name']
            new_user.last_name = self.cleaned_data['last_name']
            new_user.save()
    
            #get the profile fields information
            gender = self.cleaned_data['gender']
            ...
            pincode = self.cleaned_data['pincode']
    
            #create a new profile for this user with his information
            UserProfile(user = new_user, gender = gender, ..., pincode = pincode).save()
    
            #return the User model
            return new_user
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a registration form and validate input fields using javascript, but
I am trying to create a simple registration form. I have the following: include('User.datatype.php');
I am trying to create simple user registration form. I have an index.html file
I am trying to create a registration form (just for practice) and saw this
I'm trying to write a registration using devise and active merchant. The form is
I have two problems. problem one: I am trying to create a registeration form
I'm trying to Create a login form, and registration form. My registration form is
i'm trying to create a registration system using jsp, beans and servlets. Registration process
I'm trying to create a registration form with Rails. It's working, but it doesn't
Hi I'm trying to create a simple registration form with ajax validation. I've got

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.