Custom Search

Thursday, August 21, 2014

Django ModelAdmin add new custom column to changelist table

* Add a new item "get_userid" to list_display.
* Create a new method "get_userid" return the value you want to display in the new column in the changelist table

class StatusAdmin(admin.ModelAdmin):
    form = StatusAdminForm
    list_display = ('year', 'book', 'user', 'get_userid')

    def get_userid(self, obj):
        ##Add custom column to the table
    get_userid.short_description = 'User ID'

No comments:

Post a Comment