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 8140185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:04:35+00:00 2026-06-06T12:04:35+00:00

I have a Client model with a OneToOne relationship to User, to extend the

  • 0

I have a Client model with a OneToOne relationship to User, to extend the User model.
I need to be able to register a user (with a form that includes both the User and Client fields), and for that I used django-registration. Here is the view for registration, based on some snippets I found:

def register_client(request):
    if request.method == 'POST':
        userform = UserForm(request.POST, prefix='user')
        clientform = ClientForm(request.POST, prefix='client')
        if userform.is_valid() and clientform.is_valid():
            user = userform.save()
            client = clientform.save(commit=False)
            client.user = user
            client.save()
            login(request, user)
            return HttpResponseRedirect('/webapp/')
        else:
            return HttpResponse('error!')

    else:
        userform = UserForm(prefix='user')
        clientform = ClientForm(prefix='client')

    t = loader.get_template('register.html')
    c = RequestContext(request, {
        'userform':userform,
        'clientform':clientform,
    })
    return HttpResponse(t.render(c)) 

And here are my Forms:

from registration.forms import RegistrationForm

class UserForm(RegistrationForm):   
    def save(self):
        new_user = User.objects.create_user(
            username=self.cleaned_data['username'],
            email = self.cleaned_data['email'],
            password=self.cleaned_data['password1'])
        new_user.backend='django.contrib.auth.backends.ModelBackend'
        new_user.save()
        return new_user

class ClientForm(forms.ModelForm):
    class Meta:
        model = Client
        exclude = ['user']

I implemented the save() method for UserForm, since RegistrationForm doesn’t implement one like any typical form.

Why does one have to go through all the trouble to implement some backend in order to just save a form?
Is there any problem with this simple way? It does work.

(I also added the new_user.backend='django.contrib.auth.backends.ModelBackend' so I could login the user automatically after registration.)

  • 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-06-06T12:04:39+00:00Added an answer on June 6, 2026 at 12:04 pm

    I’m not sure how to answer your question. If your code works then I don’t see a problem. But as zaphod said, django-registration does the saving and activating of the user for you.. If you want to add extra data to your user then use django-profiles like zaphod suggested too.

    I myself use django-userena. It is like django-registration and django-profiles in one.

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

Sidebar

Related Questions

I currently have a client that wants me to 'abstract' out a domain model
I have a model with many fields (nearly 40). The client wants the fields
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I have a Client and ProposalRequest model that look like this: class Client <
I know that the asp.net repeater doesnt have a Client side object model, and
I'm on Rails 3. I have a model Client that has an address_id .
I have a User model that Devise manages - i.e. all users have email
I have following model: class Client(models.Model): user = models.OneToOneField(DjangoUser, unique=True) address = models.ForeignKey(Address,blank=True) class
I have a user model where I cannot create a client due to it
I have a client that wants to wrap the provider model with a middleware

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.