Celery Result Backends using the Django ORM/Cache framework
—
Django admin integration for browsing, searching, and managing task results through the web interface. Provides comprehensive views for task and group results with configurable read-only or editable access.
Admin interface for the TaskResult model, providing detailed views and search capabilities for task management.
class TaskResultAdmin(admin.ModelAdmin):
"""Admin interface for TaskResult model."""
model: type # TaskResult
date_hierarchy: str # 'date_done'
list_display: tuple # ('task_id', 'periodic_task_name', 'task_name', 'date_done', 'status', 'worker')
list_filter: tuple # ('status', 'date_done', 'periodic_task_name', 'task_name', 'worker')
readonly_fields: tuple # ('date_created', 'date_started', 'date_done', 'result', 'meta')
search_fields: tuple # ('task_name', 'task_id', 'status', 'task_args', 'task_kwargs')
fieldsets: tuple # Organized sections for detail view
def get_readonly_fields(self, request, obj=None):
"""
Get readonly fields based on DJANGO_CELERY_RESULTS['ALLOW_EDITS'] setting.
Args:
request: Django request object
obj: Model instance being edited (None for add)
Returns:
list: Fields that should be read-only
"""The TaskResultAdmin provides the following interface features:
List View:
Detail View Fieldsets:
Basic Information
Parameters
Result Information
# settings.py - Enable admin editing (optional)
DJANGO_CELERY_RESULTS = {
'ALLOW_EDITS': True # Default: False (read-only)
}
# Access in Django admin at /admin/django_celery_results/taskresult/
# The admin interface allows you to:
# - Browse all task results with pagination
# - Filter by status, date, task name, worker
# - Search by task ID, name, or arguments
# - View detailed task information
# - Edit task results (if ALLOW_EDITS is True)Admin interface for the GroupResult model, providing views for group task management.
class GroupResultAdmin(admin.ModelAdmin):
"""Admin interface for GroupResult model."""
model: type # GroupResult
date_hierarchy: str # 'date_done'
list_display: tuple # ('group_id', 'date_done')
list_filter: tuple # ('date_done',)
readonly_fields: tuple # ('date_created', 'date_done', 'result')
search_fields: tuple # ('group_id',)The GroupResultAdmin provides:
List View:
Detail View:
# Access in Django admin at /admin/django_celery_results/groupresult/
# The admin interface allows you to:
# - Browse all group results
# - Filter by completion date
# - Search by group ID
# - View group result detailsControl whether task results can be edited through the admin interface:
# settings.py
DJANGO_CELERY_RESULTS = {
'ALLOW_EDITS': False # Default: read-only access
}
# When ALLOW_EDITS is False:
# - All fields become read-only in admin
# - Prevents accidental modification of task results
# - Maintains data integrity
# When ALLOW_EDITS is True:
# - Standard fields become editable
# - Result, meta, date fields remain read-only
# - Allows manual correction of task dataThe admin classes are automatically registered when the app is installed:
# Automatically registered in django_celery_results.admin
from django.contrib import admin
from django_celery_results.models import TaskResult, GroupResult
admin.site.register(TaskResult, TaskResultAdmin)
admin.site.register(GroupResult, GroupResultAdmin)You can customize the admin interface by subclassing the provided admin classes:
# myapp/admin.py
from django.contrib import admin
from django_celery_results.admin import TaskResultAdmin
from django_celery_results.models import TaskResult
class CustomTaskResultAdmin(TaskResultAdmin):
# Add custom actions
actions = ['mark_as_retry']
# Customize list display
list_display = TaskResultAdmin.list_display + ('custom_field',)
def mark_as_retry(self, request, queryset):
"""Custom admin action to mark tasks for retry."""
queryset.update(status='RETRY')
self.message_user(request, "Tasks marked for retry")
mark_as_retry.short_description = "Mark selected tasks for retry"
# Unregister the default and register custom
admin.site.unregister(TaskResult)
admin.site.register(TaskResult, CustomTaskResultAdmin)The admin interface is optimized for large datasets: