This commit is contained in:
Ross
2025-12-13 22:07:07 +00:00
parent bd5ca8f64c
commit a89aa0a35b
4 changed files with 407 additions and 0 deletions
+19
View File
@@ -122,6 +122,12 @@ class Worker(models.Model):
fte = models.FloatField(default=1.0)
active = models.BooleanField(default=True)
# Store additional worker settings / metadata that map to the
# pydantic `Worker` model used by the rota generator. This allows the
# web UI to expose richer worker options without changing the core
# Django schema for frequently used fields.
options = models.JSONField(default=dict, blank=True)
rotas = models.ManyToManyField(RotaSchedule, through="Assignment", related_name="workers")
def __str__(self):
@@ -147,6 +153,19 @@ class Worker(models.Model):
"fte": int(self.fte),
}
# Merge any additional options stored on the Django model into the
# kwargs passed to the pydantic Worker model. The pydantic model will
# honour its own defaults and types; storing these as a dict keeps the
# Django DB schema simple while exposing full worker settings in the UI.
try:
opts = getattr(self, "options", None) or {}
if isinstance(opts, dict):
# shallow merge; keys in `options` override defaults above when present
pyd_kwargs.update(opts)
except Exception:
# ignore any issues reading options and proceed with core fields
pass
return PydWorker(**pyd_kwargs)