Django“xxxxxx 对象"在管理操作侧边栏中显示自定义 [英] Django "xxxxxx Object" display customization in admin action sidebar
问题描述
我想更改管理员最近更改侧边栏如何显示添加的对象"名称的默认行为.参考下图:
I would like to change the default behavior of how the admin recent changes sidebar displays the name of "objects" added. Refer to the picture below:
我想更改这些在管理员中的命名方式.理想情况下,我希望能够将其从MyModelName object"更改为,如Policy"对象示例中所示,类似于Policy: {{ value of the policy's "Policy Name" field.}}.
I would like to change how these are named in the Admin. Ideally, I would like to be able to change it from "MyModelName object" to, as in the "Policy" object example, something like "Policy: {{ value of the policy's "Policy Name" field. }}.
我在想我的 Patient 模型的 __unicode__
处理了这个,但它似乎没有.感谢您提供任何帮助.
I was thinking that __unicode__
for my Patient model handled this, but it doesn't appear to. Any assistance is appreciated.
推荐答案
__unicode__
确实做到了.您的模型应如下所示:
__unicode__
does do that. Your model should look something like this:
class SomeModel(models.Model):
def __unicode__(self):
return 'Policy: ' + self.name
在 Python 3 上,您需要使用 __str__
:
On Python 3 you need to use __str__
:
def __str__(self):
return 'Policy: ' + self.name
这篇关于Django“xxxxxx 对象"在管理操作侧边栏中显示自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!