2
0
Fork 0

implement fallback assignment admin view, dumb random fallback assignment

This commit is contained in:
Florian Sorg 2023-05-10 00:21:37 +02:00
parent 5f434adf05
commit 01ac707ab7
3 changed files with 24 additions and 1 deletions

View File

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

View File

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

View File

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