- December 8, 2007
- admin user userprofile
- 8 (after 8 ratings)
How to use:
- puts this code at the end of the
models.pyfile who haves the User Profile class declared;
- verify if your User Profile class has the name 'UserProfile'. If not, change the code to the right name.
About: this snippet makes the ORM create a profile each time an user is created (or updated, if the user profile lost), including 'admin' user.
1 2 3 4 5 6 7 8 9 10 11
# SIGNALS AND LISTENERS from django.contrib.auth.models import User from django.db.models import signals from django.dispatch import dispatcher # User def user_post_save(sender, instance, signal, *args, **kwargs): # Creates user profile profile, new = UserProfile.objects.get_or_create(user=instance) dispatcher.connect(user_post_save, signal=signals.post_save, sender=User)