覆盖Django用户模型__unicode__ [英] Override Django User model __unicode__

查看:100
本文介绍了覆盖Django用户模型__unicode__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,Django 1.2.3用户模型 unicode

Currently, Django 1.2.3 User model unicode is

def __unicode__(self):
    return self.username

我想覆盖它,以便它: p>

and I'd like to override it so its:

def __unicode__(self):
    return u'%s, %s' % (self.last_name, self.first_name)

如何?

效果:

User._meta.ordering = ['last_name', 'first_name']

在定义时工作任何地方

推荐答案

如果您需要覆盖这些,那么以后可能需要更多的自定义。
最干净的做法是使用用户个人资料模型,而不是触摸用户模型

If you need to override these, chances are you would need more customizations later on. The cleanest practice would be using a user profile models instead of touching the User model

这篇关于覆盖Django用户模型__unicode__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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