Django - Display “Model Object” in the admin page instead of Object title

女生的网名这么多〃 提交于 2020-07-03 07:06:06

问题


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.

Here is my unicode method:

def __unicode__(self):
    return self.title

回答1:


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

In Python 2.x

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

In Python 3.x

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


来源:https://stackoverflow.com/questions/33784129/django-display-model-object-in-the-admin-page-instead-of-object-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!