diff --git a/shiftregister/app/dynamic_preferences_registry.py b/shiftregister/app/dynamic_preferences_registry.py index fdd1220..068e83c 100644 --- a/shiftregister/app/dynamic_preferences_registry.py +++ b/shiftregister/app/dynamic_preferences_registry.py @@ -70,3 +70,10 @@ class EnableAsta(types.BooleanPreference): section = helper name = "enable_asta" default = True + + +@global_preferences_registry.register +class FallbackQuota(types.FloatPreference): + section = helper + name = "fallback_quota" + default = 0.7 diff --git a/shiftregister/fallback/admin.py b/shiftregister/fallback/admin.py index e2c1858..d5caad2 100644 --- a/shiftregister/fallback/admin.py +++ b/shiftregister/fallback/admin.py @@ -1,11 +1,21 @@ from django.contrib import admin -from .models import TeamMember +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 410af37..976ca66 100644 --- a/shiftregister/fallback/models.py +++ b/shiftregister/fallback/models.py @@ -3,6 +3,12 @@ from shiftregister.app.models import * class TeamMember(models.Model): name = models.CharField(max_length=100) + fallback_shifts = models.ManyToManyField(Shift, through='FallbackAssignment') + + def assign_random_shifts(self): + shifts = Shift.objects.order_by('?')[:5] + for shift in shifts: + self.fallback_shifts.add(shift) def __str__(self): return f"{self.name}"