[Improvement] Add colors to the celery admin
@@ -7,6 +7,7 @@ from celery import states
from django.db import models
from django.contrib import admin
+from django.utils.html import format_html
from project import celery_app
@@ -55,6 +56,13 @@ class CeleryTaskResultAdmin(admin.ModelAdmin):
show_full_result_count = False
search_fields = ('task_name', )
+ STATUS_COLORS = {
+ states.SUCCESS: 'green',
+ states.FAILURE: 'red',
+ states.STARTED: 'cyan',
+ states.RETRY: 'orange',
+ }
+
def get_search_results(self, request, queryset, search_term):
try:
return queryset.filter(task_id=uuid.UUID(search_term)), False
@@ -79,7 +87,11 @@ class CeleryTaskResultAdmin(admin.ModelAdmin):
return pprint.pformat(obj.meta['kwargs'])
def status_(self, obj):
- return obj.status.title()
+ return format_html(
+ '<span style="font-weight: bold; color: {}">{}</span>',
+ self.STATUS_COLORS.get(obj.status, 'black'),
+ obj.status.title()
+ )
status_.short_description = 'Status'
def meta_(self, obj):
