Skip to content

Commit

Permalink
Add min and max validators to Pay Uplift and Attrition
Browse files Browse the repository at this point in the history
  • Loading branch information
CaitBarnard committed Dec 11, 2024
1 parent 1057739 commit 055144e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from simple_history import register

Expand Down Expand Up @@ -123,6 +124,14 @@ class Meta:
),
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self._meta.get_fields():
if isinstance(field, models.FloatField):
validator = MinValueValidator(1.0)
if validator not in field.validators:
field.validators.append(validator)


class Attrition(PayModifiers):
class Meta:
Expand All @@ -139,6 +148,14 @@ class Meta:
),
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
for field in self._meta.get_fields():
if isinstance(field, models.FloatField):
validator = MaxValueValidator(1.0)
if validator not in field.validators:
field.validators.append(validator)

cost_centre = models.ForeignKey(
"costcentre.CostCentre",
on_delete=models.PROTECT,
Expand Down

0 comments on commit 055144e

Please sign in to comment.