-1

Possible Duplicate:
Creating a extended user profile

here is my User model part :

 27 class Profile(models.Model):
 28     owner = models.OneToOneField(User)
 29     title = models.CharField(max_length=20,blank=True)
 30     slogan = models.TextField(blank=True)
 31     twitter = models.URLField(blank=True)
 32     web_site = models.URLField(blank=True)
 33     email = models.EmailField(blank=True)
 34 
 35     def create_user(sender,instance,created,**kwargs):
 36         if created:
 37             Profile.objects.create(owner=instance)
 38     post_save.connect(create_user, sender=User)
 39     
 40     def __unicode__(self):
 41         return self.owner.username

in this situation ; when i create a user ; then i have to create a profile for the user which is just created.

i want to make this automatically. The User ; must create its own profile page when it s been created.

thank you.

edit : all fields have blank = True ; so it is enough just to create a blank profile object belongs to user.

Community
  • 1
  • 1
alioguzhan
  • 7,657
  • 10
  • 46
  • 67
  • 1
    [http://stackoverflow.com/questions/1910359/creating-a-extended-user-profile][1] [1]: http://stackoverflow.com/questions/1910359/creating-a-extended-user-profile – scytale Sep 24 '12 at 15:23

1 Answers1

3

This is covered explicitly in the documentation. You use signals. They even give a complete example:

# in models.py

from django.contrib.auth.models import User
from django.db.models.signals import post_save

# definition of UserProfile from above
# ...

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        UserProfile.objects.create(user=instance)

post_save.connect(create_user_profile, sender=User)
Chris Pratt
  • 232,153
  • 36
  • 385
  • 444