Skip to content

Instantly share code, notes, and snippets.

@Raisins
Created January 5, 2012 19:32
Show Gist options
  • Save Raisins/1566805 to your computer and use it in GitHub Desktop.
Save Raisins/1566805 to your computer and use it in GitHub Desktop.
UserProfile Example
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
user = models.OneToOneField(User)
#other fields here
def __str__(self):
return "%s's profile" % self.user
def create_user_profile(sender, instance, created, **kwargs):
if created:
profile, created = UserProfile.objects.get_or_create(user=instance)
post_save.connect(create_user_profile, sender=User)
User.profile = property(lambda u: u.get_profile() )
AUTH_PROFILE_MODULE = 'YOURAPP.UserProfile'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment