Django admin listview Customize Column Name

前端 未结 1 451
夕颜
夕颜 2020-12-14 06:04

Ok so I have a custom django admin built from a Author Model:

class AuthorAdmin(admin.ModelAdmin):
    \"\"\"
    Author Admin
    \"\"\"
    form = AuthorFo         


        
相关标签:
1条回答
  • 2020-12-14 06:56

    Use:

    def my_function(self, obj) :
        """My Custom Title"""
        ...
    my_function.short_description = 'This is the Column Name'
    

    It's buried in the admin docs. short_description, specifically, is barely mentioned under the discussion of list_display (more by example than actually called out). The other items like this are similiarly buried in the admin docs, but here's a summary:

    • short_description: the column title to use (string)
    • allow_tags: what the name says... let's you use HTML (True or False)
    • admin_order_field: a field on the model to order this column by (string, field name)
    • boolean: indicates the return value is boolean and signals the admin to use the nice graphic green check/red X (True or False)
    0 讨论(0)
提交回复
热议问题