User post_save signal to auto create 'admin' profile

 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)

Comments

JoshuaJenkins (on November 11, 2008):

This is no longer valid as the way dispatcher works has been updated.

Any shot at an update?

#

sasha (on November 12, 2008):

For Django 1.0:

def user_post_save(sender, instance, **kwargs):
    profile, new = UserProfile.objects.get_or_create(user=instance)

models.signals.post_save.connect(user_post_save, sender=User)

#

(Forgotten your password?)

You may use Markdown syntax here, but raw HTML will be removed.