Reputation: 1243
I am trying to setup Django to have profiles for authors. It needs to be a really simple solution and I have what I believe should work:
Model
from django.contrib.auth.models import User
class MyProfile(models.Model):
"Extends the user object for custom attr"
user = models.OneToOneField(User)
website = models.URLField(blank=True,null=True)
websiteName = models.CharField(max_length=255,blank=True,null=True)
twitterHandle=models.CharField(max_length=255,blank=True,null=True)
bio = models.TextField()
User.profile = property(lambda u: MyProfile.objects.get_or_create(user=u)[0])
def __unicode__(self):
return self.user
Settings
AUTH_PROFILE_MODULE = "btc_app.UserProfile"
However whenever I create a profile I get a type error:
Exception Value: coercing to Unicode: need string or buffer, User found
My post data looks like this
POST
website u''
bio u'tttt'
_save u'Save'
twitterHandle u''
user u'2'
websiteName u''
csrfmiddlewaretoken u'5af9526bc84673fc3338d63272804b92'
There is a drop down with all the users in it and it lets me pick one but for some reason the save fails... Any ideas?
Thanks, CG
Upvotes: 2
Views: 1751
Reputation: 3138
The problem is that in your unicode method you're returning an user instance, try something like
def __unicode__(self):
return self.user.username
Upvotes: 2