Django auth.User in Admininterface:胁迫到Unicode:需要字符串或缓冲区,用户找到 [英] Django auth.User in Admininterface: coercing to Unicode: need string or buffer, User found

查看:183
本文介绍了Django auth.User in Admininterface:胁迫到Unicode:需要字符串或缓冲区,用户找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对django很新。我尝试使用auth.User对象作为外键。



我的型号:

来自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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆