Customizing Django Admin
In this section, we’ll learn how to customize Django Admin to improve the user experience and solve different basic yet tricky requirements that come up from time to time.
Adding custom fields
Adding custom fields in Django Admin is one of the most common requirements when creating an interface. By doing so, we can add fields/information in Django Admin that are not present in the Django models. For example, to create a word_count field in Django Admin, we can use the following code:
class BlogCustom2Admin(admin.ModelAdmin):
list_display = ('title', 'word_count', 'id')
def word_count(self, obj):
return obj.content.split()
admin.site.register(models.Blog, BlogCustom2Admin) In this example, we have added a custom field called word_count to list_display that is computed using other field values.