Best way to do register a user in Django

Viewed 43859

I'm trying to implement User Registration for my Django app. The book I read mentions UserCreationForm but I need more than just name, password, and email address. I could implement my own user object and use ModelForm I think, but then I lose out on some of the django conveniences for authentication. Finally, I read something about UserProfiles which supplement Users I guess, so I think I need some combination of all of these things. Here's what I have so far.

View - this is simple enough. All I want to do here is create my form and save the user

def main(request):
    rform1 = forms.RegisterForm1()
    rform2 = forms.RegisterForm2()
    return render_to_response("authentication/index.html", {'form1': rform1, 'form2':rform2})

def register(request):
    if request.method == 'POST':
        rform1 = forms.RegisterForm1(request.POST)
        rform2 = forms.RegisterForm2(request.POST)
        if rform1.is_valid() and rform2.is_valid():
            new_user = rform1.save()
            return HttpResponseRedirect("/register-success/")
    return render_to_response("authentication/index.html", {'form1': rform1,'form2':rform2})

Form - this is my form for creating a user. Or the start of it at least

class RegisterForm1(forms.ModelForm):
    class Meta:
        model = User

class RegisterForm2(forms.ModelForm):
    class Meta:
        model = UserProfile

Model - this is my UserProfile that I want to supplement User with.

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phonenumber = PhoneNumberField()

Is it clear what I'm trying to do? Am I on the right track

2 Answers
Related