Django-显示“模型对象"在管理页面而不是对象标题中 [英] Django - Display "Model Object" in the admin page instead of Object title

查看:123
本文介绍了Django-显示“模型对象"在管理页面而不是对象标题中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如图像中所示,它显示演讲对象"而不是演讲标题.据我了解, unicode 应该注意这一点,但似乎不在这里.

As displayed in the image it displays "Lecture Object" instead of the Lecture's title. As I've understood it, unicode should take care of this, but it doesn't seem to here.

这是我的 unicode 方法:

def __unicode__(self):
    return self.title

推荐答案

要将自定义字符串显示为模型的对象表示形式,您应该:

To display a custom string as your Model's object representation, you should:

在Python 2.x中

In Python 2.x

def __unicode__(self):
    return self.some_attr  # What you want to show

在Python 3.x中

In Python 3.x

def __str__(self):
    return self.some_attr  # What you want to show

这篇关于Django-显示“模型对象"在管理页面而不是对象标题中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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