digital-branding-system/dashboard/admin.py
thecyberlearn c10d4692e6 Initial commit: Django Digital Branding Management System
- Core Django project structure with branding_system and dashboard apps
- Platform, ContentDeliverable, and Strategy models with relationships
- Comprehensive Django admin interface with custom displays
- Dashboard views with completion tracking and overdue detection
- Tailwind CSS styling with custom color scheme
- WARP.md documentation for development guidance
2025-09-07 10:16:37 +05:30

182 lines
6.8 KiB
Python

from django.contrib import admin
from django.utils.html import format_html
from .models import Platform, ContentDeliverable, Strategy
@admin.register(Platform)
class PlatformAdmin(admin.ModelAdmin):
list_display = (
'name', 'platform_type', 'status', 'primary_content_type',
'total_deliverables', 'completion_rate_display', 'created_at'
)
list_filter = ('platform_type', 'status', 'created_at')
search_fields = ('name', 'description', 'primary_content_type')
readonly_fields = ('created_at', 'updated_at')
fieldsets = (
('Basic Information', {
'fields': ('name', 'platform_type', 'status', 'primary_content_type')
}),
('Details', {
'fields': ('description', 'target_audience', 'posting_frequency')
}),
('Timestamps', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
})
)
def completion_rate_display(self, obj):
rate = obj.completion_rate
color = 'green' if rate >= 70 else 'orange' if rate >= 40 else 'red'
return format_html(
'<span style="color: {};">{:.1f}%</span>',
color, rate
)
completion_rate_display.short_description = 'Completion Rate'
def total_deliverables(self, obj):
return obj.total_deliverables
total_deliverables.short_description = 'Total Content'
class ContentDeliverableInline(admin.TabularInline):
model = ContentDeliverable
extra = 0
fields = ('title', 'content_type', 'status', 'completion_percentage', 'target_date')
readonly_fields = ()
class StrategyInline(admin.TabularInline):
model = Strategy
extra = 0
fields = ('title', 'priority', 'is_active', 'start_date', 'end_date')
@admin.register(ContentDeliverable)
class ContentDeliverableAdmin(admin.ModelAdmin):
list_display = (
'title', 'platform', 'content_type', 'status_display',
'completion_percentage_display', 'target_date', 'is_overdue_display'
)
list_filter = ('status', 'content_type', 'platform', 'target_date', 'created_at')
search_fields = ('title', 'description', 'tags', 'platform__name')
readonly_fields = ('created_at', 'updated_at', 'days_until_due')
date_hierarchy = 'target_date'
fieldsets = (
('Basic Information', {
'fields': ('platform', 'title', 'content_type', 'status')
}),
('Content Details', {
'fields': ('description', 'completion_percentage', 'tags')
}),
('Dates', {
'fields': ('target_date', 'actual_date', 'days_until_due')
}),
('Additional Info', {
'fields': ('url', 'notes')
}),
('Timestamps', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
})
)
def status_display(self, obj):
status_colors = {
'committed': 'blue',
'drafted': 'orange',
'published': 'green',
'cancelled': 'red'
}
color = status_colors.get(obj.status, 'black')
return format_html(
'<span style="color: {}; font-weight: bold;">{}</span>',
color, obj.get_status_display()
)
status_display.short_description = 'Status'
def completion_percentage_display(self, obj):
percentage = obj.completion_percentage
if percentage == 100:
color = 'green'
elif percentage >= 50:
color = 'orange'
else:
color = 'red'
return format_html(
'<div style="width: 100px; background-color: #f0f0f0; border-radius: 3px; padding: 2px;">' +
'<div style="width: {}%; background-color: {}; height: 20px; border-radius: 2px; text-align: center; color: white; line-height: 20px; font-size: 12px;">' +
'{}%</div></div>',
percentage, color, percentage
)
completion_percentage_display.short_description = 'Progress'
def is_overdue_display(self, obj):
if obj.is_overdue:
return format_html('<span style="color: red; font-weight: bold;">⚠ OVERDUE</span>')
elif obj.days_until_due is not None and obj.days_until_due <= 3 and obj.status != 'published':
return format_html('<span style="color: orange;">⏰ Due Soon</span>')
return ''
is_overdue_display.short_description = 'Due Status'
actions = ['mark_as_drafted', 'mark_as_published', 'mark_as_committed']
def mark_as_drafted(self, request, queryset):
updated = queryset.update(status='drafted')
self.message_user(request, f'{updated} deliverables marked as drafted.')
mark_as_drafted.short_description = 'Mark selected items as drafted'
def mark_as_published(self, request, queryset):
updated = queryset.update(status='published', completion_percentage=100)
self.message_user(request, f'{updated} deliverables marked as published.')
mark_as_published.short_description = 'Mark selected items as published'
def mark_as_committed(self, request, queryset):
updated = queryset.update(status='committed')
self.message_user(request, f'{updated} deliverables marked as committed.')
mark_as_committed.short_description = 'Mark selected items as committed'
@admin.register(Strategy)
class StrategyAdmin(admin.ModelAdmin):
list_display = ('title', 'platform', 'priority', 'is_active', 'start_date', 'end_date')
list_filter = ('platform', 'priority', 'is_active', 'start_date')
search_fields = ('title', 'objective', 'tactics', 'actions')
readonly_fields = ('created_at', 'updated_at')
fieldsets = (
('Basic Information', {
'fields': ('platform', 'title', 'priority', 'is_active')
}),
('Strategy Details', {
'fields': ('objective', 'tactics', 'actions', 'control')
}),
('Timeline', {
'fields': ('start_date', 'end_date')
}),
('Timestamps', {
'fields': ('created_at', 'updated_at'),
'classes': ('collapse',)
})
)
actions = ['activate_strategies', 'deactivate_strategies']
def activate_strategies(self, request, queryset):
updated = queryset.update(is_active=True)
self.message_user(request, f'{updated} strategies activated.')
activate_strategies.short_description = 'Activate selected strategies'
def deactivate_strategies(self, request, queryset):
updated = queryset.update(is_active=False)
self.message_user(request, f'{updated} strategies deactivated.')
deactivate_strategies.short_description = 'Deactivate selected strategies'
# Customize admin site headers
admin.site.site_header = "Digital Branding Management System"
admin.site.site_title = "Branding Admin"
admin.site.index_title = "Welcome to Digital Branding Management"