project/kiwipycon/user/models.py
changeset 1 fda1c66b25f9
equal deleted inserted replaced
0:9a77edda77b7 1:fda1c66b25f9
       
     1 # -*- coding: utf-8 -*-
       
     2 from __future__ import absolute_import
       
     3 
       
     4 #django
       
     5 from django.db import models
       
     6 from django.conf import settings
       
     7 from django.db.models.signals import post_save
       
     8 from django.contrib.auth.models import User
       
     9 
       
    10 class UserProfile(models.Model):
       
    11     """
       
    12     Extend atributes for django User
       
    13     """
       
    14     user = models.ForeignKey(User, unique=True)
       
    15     url = models.URLField(blank=True, verify_exists=False)
       
    16     photo = models.CharField(max_length=64, blank=True)
       
    17     about = models.TextField(blank=True)
       
    18 
       
    19     def __unicode__(self):
       
    20         return 'UserProfile for user: <%s %s> %s' % (self.user.first_name,
       
    21                 self.user.last_name, self.user.email)
       
    22 
       
    23     def fullname(self):
       
    24         return '%s %s' % (self.user.first_name, self.user.last_name)
       
    25 
       
    26 def add_profile(sender, instance, signal, *args, **kwargs):
       
    27     """Create user profile on create of new user"""
       
    28     if not instance.is_superuser:
       
    29         try:
       
    30             profile, new = UserProfile.objects.get_or_create(user=instance)
       
    31             if new:
       
    32                 profile.save()
       
    33         except:
       
    34             pass
       
    35 
       
    36 post_save.connect(add_profile, sender=User, weak=False)