问题描述
我想更改默认行为,以便管理员最近更改侧边栏显示添加的对象的名称。请参阅下图:
我想更改管理中如何命名这些对象。理想情况下,我希望能够将其从MyModelName对象更改为Policy对象示例,如Policy:{{policy of the policy'sPolicy Name)。}}。 >
我以为我的患者模型处理了这个 __ unicode __
,但似乎没有任何帮助。
__ unicode __
做到这一点,你的模型应该是这样的:
class SomeModel(models.Model):
def __unicode __(self):
return' :'+ self.name
在Python 3中,您需要使用 __ str __
def __str __(self):
return'Policy:'+ self.name
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:
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. }}.
I was thinking that __unicode__
for my Patient model handled this, but it doesn't appear to. Any assistance is appreciated.
__unicode__
does do that. Your model should look something like this:
class SomeModel(models.Model):
def __unicode__(self):
return 'Policy: ' + self.name
On Python 3 you need to use __str__
:
def __str__(self):
return 'Policy: ' + self.name
这篇关于Django“xxxxxx对象”在管理操作侧栏中显示自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!