← Back to Chapters

Customizing Django Admin List View

?️ Customizing Django Admin List View

? Quick Overview

The Django admin interface can be customized to improve the user experience. You can modify how models are displayed, enable search functionality, add filters, and customize the layout of list views.

? Key Concepts

  • list_display – Controls visible columns
  • search_fields – Enables admin search
  • list_filter – Adds sidebar filters
  • ordering – Default record sorting

? Syntax / Theory

Django provides the ModelAdmin class to customize how models appear in the admin panel. You extend this class and configure options to control display, search, and filtering behavior.

? Code Example: List Display

? View Code Example
# Custom admin configuration for Product model
from django.contrib import admin
from .models import Product

class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'stock', 'created_at')

admin.site.register(Product, ProductAdmin)

? Code Example: Search

? View Code Example
# Enable search by name and description
class ProductAdmin(admin.ModelAdmin):
search_fields = ('name', 'description')

? Code Example: Filters

? View Code Example
# Add sidebar filters in admin list view
class ProductAdmin(admin.ModelAdmin):
list_filter = ('category', 'price')

? Code Example: Ordering

? View Code Example
# Sort products by newest first
class ProductAdmin(admin.ModelAdmin):
ordering = ('-created_at',)

? Live Output / Explanation

After applying these configurations, the Django admin panel will show structured columns, search input, filter sidebar, and ordered records—making data management faster and cleaner.

? Interactive Example

Try the simulator below. Use the Search box, click the Column Headers to sort, or use the Sidebar to filter by category.

?
Product Name ↕ Price ↕ Status ↕

By Category

? Use Cases

  • Managing products in e-commerce admin
  • Filtering users or orders quickly
  • Improving admin productivity

✅ Tips & Best Practices

  • Use list_display for clarity
  • Search only necessary fields
  • Filters work best with categories and dates
  • Order by frequently used fields

? Try It Yourself

  • Add a computed field to list_display
  • Experiment with date filters
  • Enable search on foreign key fields