diff --git a/competition/models.py b/competition/models.py index 8af195ff..07322ad8 100644 --- a/competition/models.py +++ b/competition/models.py @@ -22,6 +22,7 @@ from competition.querysets import ActiveQuerySet from competition.utils.school_year_manipulation import \ get_school_year_end_by_date +from competition.utils.validations import validate_points from personal.models import Profile, School from user.models import User @@ -657,7 +658,7 @@ class Meta: verbose_name='opravené riešenie', blank=True, upload_to=get_corrected_solution_path) score = models.PositiveSmallIntegerField( - verbose_name='body', null=True, blank=True) + verbose_name='body', null=True, blank=True, validators=[validate_points]) vote = models.IntegerField(choices=Vote.choices, default=Vote.NONE) diff --git a/competition/utils/validations.py b/competition/utils/validations.py new file mode 100644 index 00000000..1ca7479a --- /dev/null +++ b/competition/utils/validations.py @@ -0,0 +1,8 @@ +from django.core.exceptions import ValidationError + + +def validate_points(value: int): + if value < 0 or value > 9: + raise ValidationError( + f'{value} je mimo povoleného rozmedzia pre body' + )