Django auth.User in Admininterface:胁迫到Unicode:需要字符串或缓冲区,用户找到 [英] Django auth.User in Admininterface: coercing to Unicode: need string or buffer, User found
问题描述
我的型号:
来自django.contrib.auth.models的用户
class Entry(models.Model):
( ...)
user = models.ForeignKey(User)
date = models.DateTimeField()
def __unicode __(self):
return self.user
当在管理界面中创建一个用户的新条目时,我得到:强制为Unicode:需要字符串或缓冲区,用户发现
异常类型:TypeError
异常值:强制为Unicode:需要字符串或缓冲区,用户
发现
异常
位置:/ Library / Python /2.7/site-packages/django/utils/encoding.py
在force_unicode,第71行
我什么失踪
这个工作和解释本身
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b
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?
this should work and explain itself
def __unicode__(self):
return unicode(self.user)
这篇关于Django auth.User in Admininterface:胁迫到Unicode:需要字符串或缓冲区,用户找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!