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_displayto choose which fields and callables appear as columns in the list view. -
Add a method like
status_badgeto show computed/pretty values; set.short_descriptionfor the column header. -
list_display_linkscontrols which columns link to the change page;list_editableenables 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
Previous snippet
Reverse URL in Templates
Next snippet