Saving profile with registration in Django-Registration
Asked Answered
R

3

14

In Django-Registration it says you can save a custom profile when you save a user.
But I have no idea what the documentation is asking me to do. Here is what they say:

To enable creation of a custom user profile along with the User (e.g., the model specified in the AUTH_PROFILE_MODULE setting), define a function which knows how to create and save an instance of that model with appropriate default values, and pass it as the keyword argument profile_callback. This function should accept one keyword argument:

user

The User to relate the profile to.

Can someone give me an example of the function that needs to be created and how to pass it as a argument?

Rosarosabel answered 2/7, 2009 at 3:10 Comment(0)
P
8

You can pass the callback function in your urls.py file.

from mysite.profile.models import UserProfile


url( r'^accounts/register/$',      'registration.views.register',
        { 'profile_callback': UserProfile.objects.create }, name = 'registration_register' ),

Substitute your own function for UserProfile.objects.create as needed.

Practitioner answered 2/7, 2009 at 5:53 Comment(2)
Well, i need to do the same...but i can undestand how ill show the profile form in the sample place of the register form and save the data... i dont know im lost...thanksRaymonderaymonds
This is no longer the case in django-registration 0.8+Nishanishi
P
6

This is covered in this blogpost and expanded on in my answer to another question on the same issue

django-registration sends a signal at various events happening - registration and activation. At either of those points you can create a hook to that signal which will be given the user and request objects - from there you can create a profile for that user.

The signal from django-registration

#registration.signals.py 
user_registered = Signal(providing_args=["user", "request"]) 

Code to create profile

#signals.py (in your project)
user_registered.connect(create_profile)

def create_profile(sender, instance, request, **kwargs):
    from myapp.models import Profile
    #If you want to set any values (perhaps passed via request) 
    #you can do that here

    Profile(user = instance).save()
Peyton answered 7/4, 2011 at 13:12 Comment(0)
M
1

For anyone who met this problem, I think this blog post is a good tutorial: http://johnparsons.net/index.php/2013/06/28/creating-profiles-with-django-registration/.

Misgiving answered 12/4, 2014 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.