Django Admin Configuration
Commandby davila7 · Added 5mo ago
Claude
Install
npx claude-code-templates@latest --command=cli-tool/templates/python/examples/django-app/.claude/commands --yesAdd to Claude
claude mcp add django-admin-configurationAbout
Django Admin Configuration
Configure Django admin interface with custom admin classes and functionality.
Purpose
This command helps you create comprehensive Django admin configurations with advanced features and customizations.
Usage
/admin
What this command does
- Registers models with custom admin classes
- Creates advanced admin interfaces with filtering, search, and actions
- Adds inline editing for related models
- Customizes list displays and forms
- Implements admin actions for bulk operations
Example Output
# admin.py
from django.contrib import admin
from django.utils.html import format_html
from django.urls import reverse
from django.utils.safestring import mark_safe
from .models import Post, Category, Tag, Comment
@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
"""Admin configuration for Category model."""
list_display = ['name', 'slug', 'post_count', 'created_at']
list_filter = ['created_at']
search_fields = ['name', 'description']
prepopulated_fields = {'slug': ('name',)}
readonly_fields = ['created_at', 'updated_at']
def post_count(self, obj):
"""Display number of posts in this category."""
count = obj.posts.count()
url = reverse('admin:blog_post_changelist') + f'?category__id__exact={obj.id}'
return format_html('<a href="{}">{} posts</a>', url, count)
post_count.short_description = 'Posts'
class CommentInline(admin.TabularInline):
"""Inline admin for comments."""
model = Comment
extra = 0
readonly_fields = ['created_at', 'author']
fields = ['author', 'content', 'is_approved', 'created_at']
@admin.register(Post)
class PostAdmin(admin.ModelAdmin):
"""Advanced admin configuration for Post model."""
list_display = [
'title',
'author',
'category',
'status',
'view_count',
'created_at',
'post_preview'
]
list_filt
Tags
CodeAnalysisaitmplclaude-code-templates