Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django auth.User in Admininterface: coercing to Unicode: need string or buffer, User found

I'm pretty new to django. I try to use the auth.User object as a foreign key.

My model:

from django.contrib.auth.models import User

(...)

class Entry(models.Model):
    (...)
    user = models.ForeignKey(User)
    date = models.DateTimeField()
    def __unicode__(self):
        return self.user

When creating a new Entry with a user in admin interface, i get: "coercing to Unicode: need string or buffer, User found"

Exception Type: TypeError

Exception Value: coercing to Unicode: need string or buffer, User found

Exception Location: /Library/Python/2.7/site-packages/django/utils/encoding.py in force_unicode, line 71

What am i missing?

like image 607
patchrail Avatar asked Sep 13 '11 09:09

patchrail


1 Answers

this should work and explain itself

def __unicode__(self):
    return unicode(self.user)
like image 61
Tommaso Barbugli Avatar answered Nov 15 '22 11:11

Tommaso Barbugli