107
Use:
class AuthorAdmin(admin.ModelAdmin):
…
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
orFalse
)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
orFalse
)
9
Starting from Django 3.2 you can use the display
decorator. It has the attribute description
for changing the name of the column:
class AuthorAdmin(admin.ModelAdmin):
list_display = ['profile_photo', 'first_name', 'last_name', 'title']
@admin.display(description='Profile Photo')
def profile_photo(self, obj) :
return '<img src="%s" title="%s" />' % (resize_image(obj.photo, '100x100'), obj.title)
For more info about the display
decorator see this page
- [Django]-What is an efficient way of inserting thousands of records into an SQLite table using Django?
- [Django]-How to add custom search box in Django-admin?
- [Django]-Is there a way to filter a queryset in the django admin?
1
Inside your models.py model class you can simply do as follows for (usually) any field:
your_field = models.CharField(max_length=123456789, verbose_name="WOWYWOWY!!!")
- [Django]-Difference between filter with multiple arguments and chain filter in django
- [Django]-How to install libpq-fe.h?
- [Django]-POST jQuery array to Django
Source:stackexchange.com