Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return __str__(self) in ModelAdmin list_display

I have the following model:

class Administrator(models.Model):
    // code

    def __str__(self):
        title = 'Administrator ' + str(self.pk)
        return title

This returns titles for the objects as Administrator 1, Administrator 2, etc.

How do I return the title in list_display for a ModelAdmin?:

class AdministratorAdmin(ModelAdmin):
    model = Administrator
    list_display = ('pk', 'id', 'title???')
like image 758
alias51 Avatar asked Dec 08 '22 11:12

alias51


1 Answers

I think it should be:

class AdministratorAdmin(ModelAdmin):
    model = Administrator
    list_display = ('pk', 'id', '__str__')
like image 184
saharsh_bhatia Avatar answered Mar 09 '23 15:03

saharsh_bhatia