.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user