Customize list_display in Admin

A snippet showing how to customize Django admin list_display.


# models.py

from django.db import models

class Product(models.Model):
    name = models.CharField(max_length=150)
    category = models.CharField(max_length=80)
    price = models.DecimalField(max_digits=8, decimal_places=2)
    is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name
  

# admin.py

from django.contrib import admin
from .models import Product

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('name', 'category', 'price', 'is_active', 'created_at', 'status_badge')
    list_display_links = ('name',)
    list_editable = ('is_active',)
    ordering = ('-created_at',)

    def status_badge(self, obj):
        return "Active" if obj.is_active else "Inactive"
    status_badge.short_description = 'Status'
  
Explanation:
  • Use list_display to choose which fields and callables appear as columns in the list view.
  • Add a method like status_badge to show computed/pretty values; set .short_description for the column header.
  • list_display_links controls which columns link to the change page; list_editable enables inline editing.
  • Keep columns concise-too many fields can slow the page and hurt readability.
  • Category Admin
  • Total Views 1099
  • Last Modified 02 October, 2025
  • Tags #admin #list_display #models #customization
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.