diff --git a/competition/models.py b/competition/models.py index 99da75d..d451a4f 100644 --- a/competition/models.py +++ b/competition/models.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.sites.models import Site +from django.core.exceptions import ValidationError from django.core.files.storage import FileSystemStorage from django.core.validators import validate_slug from django.db import models @@ -236,6 +237,12 @@ class Meta: blank=True, default=None) + def clean(self) -> None: + if self.season_code == 2: + raise ValidationError( + 'Seminár musí byť zimný alebo letný(season_code 0 alebo 1)') + return super().clean() + def save(self, *args, **kwargs) -> None: if not self.frozen_results: self.frozen_results = None diff --git a/competition/serializers.py b/competition/serializers.py index b39c517..c90ce14 100644 --- a/competition/serializers.py +++ b/competition/serializers.py @@ -1,6 +1,7 @@ from django.contrib.auth.models import AnonymousUser from django_typomatic import ts_interface from rest_framework import serializers +from rest_framework.exceptions import ValidationError from competition import models from personal.serializers import ProfileShortSerializer, SchoolShortSerializer @@ -392,6 +393,13 @@ class Meta: model = models.Semester exclude = ['frozen_results', 'registration_link'] read_only_fields = ['complete'] + validators = [] + + def validate(self, attrs): + if attrs.get('season_code', 0) not in (0, 1): + raise ValidationError( + 'Seminár musí byť zimný alebo letný(season_code 0 alebo 1)') + return super().validate(attrs) def get_complete(self, obj: models.Semester): return obj.complete