Daniel,

thanks much. That was the problem.

Damn -- its so freakishly easy to miss such nasty little things when
you're over worked :-)

thanks again.

-pranav.

On Feb 26, 4:03 pm, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On Feb 26, 8:12 pm, "uno...@gmail.com" <uno...@gmail.com> wrote:
>
>
>
> > I have the following model form:
>
> > class EditProfileForm(ModelForm):
>
> >     class Meta:
> >         model = UserProfile
> >         exclude = ('user',)
>
> > The corresponding model is:
>
> > class UserProfile(models.Model):
>
> >     user = models.ForeignKey(User)
> >     firstname = models.CharField(max_length=50,blank=True)
> >     lastname = models.CharField(max_length=50,blank=True)
> >     blog = models.URLField(blank=True)
> >     location = models.CharField(max_length=50,blank=True)
> >     karma = models.IntegerField(editable=False,default="0")
>
> > and the view is:
>
> > def editprofile(request):
>
> >     user = request.user
> >     profile = UserProfile.objects.get_or_create(user=user)
>
> >     if request.method == "POST":
>
> >         form = EditProfileForm(request.POST,instance=profile)
> >         if form.is_valid():
> >             profile = form.save()
> >             return HttpResponseRedirect("/myprofile/")
> >     else:
> >         form = EditProfileForm(instance=profile)
>
> >     return render_to_response("editprofile.html",{"form":form},
> >                               context_instance=RequestContext
> > (request))
>
> > I keep getting the following error:
>
> > AttributeError: 'tuple' object has no attribute '_meta'
>
> > on the line:  form = EditProfileForm(instance=profile)
>
> > any ideas what's wrong here ?
>
> Your problem is in this line:
> profile = UserProfile.objects.get_or_create(user=user)
>
> Look closely at the documentation for the get_or_create method 
> -http://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-cre...
> You'll see it returns *two* arguments: the object, and a boolean to
> show whether or not the object was newly created. Because you have
> only given one name on the left-hand side of the assignment, Python
> packs the two values into a tuple, which explains your error message.
>
> Instead, use two variables:
> profile, created = UserProfile.objects.get_or_create(user=user)
> and all should be fine.
> --
> DR.
--~--~---------~--~----~------------~-------~--~----~
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