Django “xxxxxx Object” display customization in admin action sidebar

前端 未结 9 1035
野的像风
野的像风 2020-12-02 10:07

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:

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 10:45

    __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
    

提交回复
热议问题