diff --git a/shiftregister/fallback/admin.py b/shiftregister/fallback/admin.py index f616d1a..0ffe4ab 100644 --- a/shiftregister/fallback/admin.py +++ b/shiftregister/fallback/admin.py @@ -1,21 +1,22 @@ from django.contrib import admin from .models import * + def assign_random_shifts(modeladmin, request, queryset): for member in queryset: member.assign_random_shifts() - # Register your models here. + class FallbackAssignmentInline(admin.TabularInline): model = FallbackAssignment + @admin.register(TeamMember) class TeamMemberAdmin(admin.ModelAdmin): fields = ["name"] list_display = ["name"] inlines = (FallbackAssignmentInline,) actions = (assign_random_shifts,) - diff --git a/shiftregister/fallback/models.py b/shiftregister/fallback/models.py index 976ca66..13ce066 100644 --- a/shiftregister/fallback/models.py +++ b/shiftregister/fallback/models.py @@ -3,10 +3,10 @@ from shiftregister.app.models import * class TeamMember(models.Model): name = models.CharField(max_length=100) - fallback_shifts = models.ManyToManyField(Shift, through='FallbackAssignment') + fallback_shifts = models.ManyToManyField(Shift, through="FallbackAssignment") def assign_random_shifts(self): - shifts = Shift.objects.order_by('?')[:5] + shifts = Shift.objects.order_by("?")[:5] for shift in shifts: self.fallback_shifts.add(shift)