Sunday 15 April 2012

Extending user with user profile in django(1.3) -


I am following a link to expand the DJJong user in a user profile. Import django.contrib.auth.models from the user

  # Models.py import django.db.models.signals from user post_save class UserProfile (models.Model): user = models.OneToOneField ( User) emailId = models.CharField (max_length = 200) dated = model.DataFilefield (empty = true, zero = true) #other field here def __str __ (self): Return "Profile of% s"% self.user def create_user_profile (Sender, example, created, ** kwargs): if created: profile, created = user profile.blogs.jet_core (user = instance) post_save.connect (create_user_profile, using sender =) I am not sure how I will create users like user profiles and users both are created and user profile such as e-mail address. Mail etc., the date is composed of the population?  

In the thoughts I have the following

  DIF register _user (request): json_data = json.loads (request.raw_post_data) email = json_data ['email']. Less () pwd = json_data ['password'] # Hard-coded values ​​for testing UserProfile.user = User.objects user profile, user profile.objects. IF = Email, User Profile. Password = PWD   

, but I get an error: 'UserProfile' does not have any attribute in the object 'user_id' I think I am here somewhere I am getting the concepts. Any help is appreciated.

Thanks for the answer, the code provided by you worked! I was also able to do the following:

  user = user.bizs.create_user ('john', email, pwd) userProfile = user.get_profile () userProfile.emailId = email User.save () userProfile.save ()   

If both are equal, or if there is a benefit of one above one using get_profile () then

Thanks again!

You are trying to allocate directly to your user profile class, here:

  UserProofile.user = User.objects.create_user ('john', email, pwd)   

You want something like this:

 < Code> new_user = User.objects.create_user ('john', email, pwd) userProfile, created = UserProfile.objects.get_or_create (user = new_user, default = {'useremailId': email})    

No comments:

Post a Comment