Give this a shot:

user = User.objects.create_user(request.POST['apelido'],
request.POST['email'], request.POST['pwd'])
user.save()
profile = user.get_profile()
profile.apelido = request.POST['apelido']
profile.save()

Also, I recommend using Forms (and better yet, ModelForms with Class-Based
Views) to sanitize and validate your data.

On Mon, Jun 18, 2012 at 9:50 AM, upmauro <upma...@gmail.com> wrote:

> Sorry my english.
>
> In my *models.py*
>
> class Usuario(models.Model):
>     user = models.ForeignKey(User,primary_key=True)
>     apelido = models.CharField(max_length=75, blank=True)
>     class Meta:
>         db_table = u'usuario'
>
> def create_user_profile(sender, instance, created, **kwargs):
>     if created:
>        profile, created = Usuario.objects.get_or_create(user=instance)
>
> post_save.connect(create_user_profile, sender=User)
>
> In my *views.py*
> *
> *
> @csrf_exempt
> def register(request):
>     user = User.objects.create_user(request.POST['apelido'],
> request.POST['email'], request.POST['pwd'])
>     user.get_profile().apelido = request.POST['apelido']
>
> *
> *
> *Error:*
> *
> *
> Exception Value:
> Usuario matching query does not exist
>
> *Line:*.
>
> user.get_profile().apelido = request.POST['apelido']
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/c0qZCUUHsGEJ.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to