python - Django UserProfile signals create user, first_name, last_name -


when i'm creating userprofile using user data, want pass first_name , last_name well.

here models.py

class userprofile(models.model):     user = models.onetoonefield(settings.auth_user_model)     first_name = models.charfield(max_length=200, blank=true, null=true, default=none)     last_name = models.charfield(max_length=200, blank=true, null=true, default=none)  def post_save_user(sender, instance, created, **kwargs):     if created:         userprofile.objects.create(user=instance)   post_save.connect(post_save_user, sender=settings.auth_user_model) 

i've tried using userprofile.objects.create(user=instance, first_name=instance.first_name, last_name=instance.last_name) , it's creating profile it's not adding first_name , last_name.

question: how can add first_name , last_name profile using user data?

you don't expect magic happen, you? try extending signal receiver this:

def post_save_user(sender, instance, created, **kwargs):     if created:         userprofile.objects.create(             user=instance,             first_name=instance.first_name,             last_name=instance.last_name,         ) 

but, being honest, answer belongs in trash bin: @daniel-roseman pointed out, store redundant data. if want there separate userprofile model, consider making first_name , last_name @property (possibly @_.setter) operate data stored in auth.user model.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -