From 962dc9765231bfe1629b6e220ac1460864e48888 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 | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/django_celery_beat/admin.py b/django_celery_beat/admin.py index 1da5fd65..983c29a8 100644 --- a/django_celery_beat/admin.py +++ b/django_celery_beat/admin.py @@ -261,8 +261,26 @@ 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 = ( @@ -274,11 +292,22 @@ class ClockedScheduleAdmin(admin.ModelAdmin): @admin.register(CrontabSchedule) -class CrontabScheduleAdmin(admin.ModelAdmin): +class CrontabScheduleAdmin(ScheduleAdmin): """Admin class for CrontabSchedule.""" list_display = ('__str__', 'human_readable') + 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.site.register(IntervalSchedule) -admin.site.register(SolarSchedule) +@admin.register(IntervalSchedule) +class IntervalScheduleAdmin(ScheduleAdmin): + """Admin class for IntervalSchedule.""" + pass