Problem using User.get_profile() in DJANGO

273 views
Skip to first unread message

upmauro

unread,
Jun 18, 2012, 9:50:18 AM6/18/12
to django...@googlegroups.com
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'] 

Kurtis Mullins

unread,
Jun 18, 2012, 10:29:55 AM6/18/12
to django...@googlegroups.com
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.

--
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...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

upmauro

unread,
Jun 18, 2012, 2:37:03 PM6/18/12
to django...@googlegroups.com
Solve, thank you !
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages