Django auth.User in Admininterface: forced to Unicode: need string or buffer found by user

I am new to django. I am trying to use an 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 record with a user in the admin interface, I get: "coercing to Unicode: need string or buffer, User found"

Exception Type: TypeError

Exception value: Unicode forced: string or buffer needed, user found

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

What am I missing?

+6
source share
1 answer

it should work and explain itself

 def __unicode__(self): return unicode(self.user) 
+24
source

Source: https://habr.com/ru/post/897212/


All Articles