CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-django-celery-results

Celery Result Backends using the Django ORM/Cache framework

Pending
Overview
Eval results
Files

admin.mddocs/

Admin Interface

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.

Capabilities

Task Result Administration

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
        """

Admin Configuration

The TaskResultAdmin provides the following interface features:

List View:

  • Displays: task_id, periodic_task_name, task_name, date_done, status, worker
  • Filters: status, date_done, periodic_task_name, task_name, worker
  • Search: task_name, task_id, status, task_args, task_kwargs
  • Date hierarchy: Organized by date_done for easy navigation

Detail View Fieldsets:

  1. Basic Information

    • task_id, task_name, periodic_task_name
    • status, worker
    • content_type, content_encoding
  2. Parameters

    • task_args (task positional arguments)
    • task_kwargs (task keyword arguments)
  3. Result Information

    • result (task return value)
    • date_created, date_started, date_done
    • traceback (if task failed)
    • meta (task metadata)

Usage Example

# 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)

Group Result Administration

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',)

Group Admin Configuration

The GroupResultAdmin provides:

List View:

  • Displays: group_id, date_done
  • Filters: date_done
  • Search: group_id
  • Date hierarchy: Organized by date_done

Detail View:

  • All fields with date_created, date_done, result as read-only
  • Full group result content display

Usage Example

# 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 details

Configuration

Admin Access Control

Control 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 data

Admin Registration

The 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)

Customizing Admin Views

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)

Security Considerations

  • Read-only by default: Prevents accidental modification of task results
  • Field-level restrictions: Sensitive fields (result, meta) remain read-only even when editing is enabled
  • Permission-based access: Respects Django's built-in admin permissions
  • Search limitations: Search fields are carefully selected to avoid performance issues with large datasets

Performance Optimization

The admin interface is optimized for large datasets:

  • Database indexes: All list_display and list_filter fields have database indexes
  • Pagination: Large result sets are automatically paginated
  • Date hierarchy: Efficient navigation through time-based data
  • Limited search fields: Search is restricted to indexed fields to maintain performance

Install with Tessl CLI

npx tessl i tessl/pypi-django-celery-results

docs

admin.md

backends.md

index.md

models.md

views.md

tile.json