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

前端 未结 1 1156
庸人自扰
庸人自扰 2021-01-18 19:44

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 d

1条回答
  •  清歌不尽
    2021-01-18 20:33

    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
    

    0 讨论(0)
提交回复
热议问题