From 797dbf18c25c526e7ad18e0479fc585943bf0584 Mon Sep 17 00:00:00 2001 From: Doug Harris Date: Mon, 11 Mar 2024 10:35:17 -0400 Subject: [PATCH] Adding inline to each schedule admin to show PeriodicTasks using the schedule For issue #742 --- django_celery_beat/admin.py | 38 ++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 1da5fd65..5c240fb2 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -261,8 +261,24 @@ def run_tasks(self, request, queryset): ) +class PeriodicTaskInline(admin.TabularInline): + model = PeriodicTask + fields = ('name', 'task', 'args', 'kwargs') + readonly_fields = fields + can_delete = False + extra = 0 + show_change_link = True + verbose_name = "Periodic Tasks Using This Schedule" + verbose_name_plural = verbose_name + + def has_add_permission(self, request, obj): + return False + +class ScheduleAdmin(admin.ModelAdmin): + inlines = [PeriodicTaskInline] + @admin.register(ClockedSchedule) -class ClockedScheduleAdmin(admin.ModelAdmin): +class ClockedScheduleAdmin(ScheduleAdmin): """Admin-interface for clocked schedules.""" fields = ( @@ -272,13 +288,21 @@ class ClockedScheduleAdmin(admin.ModelAdmin): 'clocked_time', ) - @admin.register(CrontabSchedule) -class CrontabScheduleAdmin(admin.ModelAdmin): +class CrontabScheduleAdmin(ScheduleAdmin): """Admin class for CrontabSchedule.""" list_display = ('__str__', 'human_readable') - - -admin.site.register(IntervalSchedule) -admin.site.register(SolarSchedule) + fields = ('human_readable', 'minute', 'hour', 'day_of_month', + 'month_of_year', 'day_of_week', 'timezone') + readonly_fields = ('human_readable', ) + +@admin.register(SolarSchedule) +class SolarScheduleAdmin(ScheduleAdmin): + """Admin class for SolarSchedule.""" + pass + +@admin.register(IntervalSchedule) +class IntervalScheduleAdmin(ScheduleAdmin): + """Admin class for IntervalSchedule.""" + pass