Django “xxxxxx Object” display customization in admin action sidebar

前端 未结 9 1037
野的像风
野的像风 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:57

    By adding __str__() method to the model Patient this way:

    class Patient(models.Model):
    name=models.CharField(max_length=200)
    #.........
    def __str__(self):
        return self.name
    

    will display name of patient instead object. For detail check here

    0 讨论(0)
  • 2020-12-02 11:04

    You need to define, which column that you want to display...

    for example:

    class POAdmin(admin.ModelAdmin):
        list_display = ('qty', 'cost', 'total')
    
    0 讨论(0)
  • 2020-12-02 11:07

    The string you're seeing is coming from __unicode__ method, as others have mentioned. But the thing is that admin saves string representation of an object when it creates log event, therefore if you add __unicode__ implementation after the log entry was saved, you won't see new titles on old items, only after you make some new activity

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