Refactor Assignment model to enforce single rota assignment per worker and update related view logic to prevent multiple assignments

This commit is contained in:
Ross
2025-12-19 21:10:43 +00:00
parent f4ab0be347
commit 5cf2480602
3 changed files with 59 additions and 8 deletions
@@ -0,0 +1,16 @@
from django.core.management.base import BaseCommand
from django.db.models import Count
from rota.models import Worker
class Command(BaseCommand):
help = "List workers assigned to more than one rota (useful before migrating to OneToOne Assignment)"
def handle(self, *args, **options):
qs = Worker.objects.annotate(num_rotas=Count('rotas')).filter(num_rotas__gt=1)
if not qs.exists():
self.stdout.write(self.style.SUCCESS('No workers assigned to more than one rota.'))
return
for w in qs:
self.stdout.write(f"Worker id={w.id} name={w.name!r} assigned_rotas={w.num_rotas}")