Skip to content

Commit

Permalink
Pridaná validácia na ročník pre Event registration
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Dec 13, 2024
1 parent c9c18cc commit 0846eaf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions competition/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ class Meta:
event = serializers.PrimaryKeyRelatedField(
queryset=models.Event.objects.all())

def validate(self, attrs):
grade: models.Grade | None = attrs.get('grade')
event: models.Event | None = attrs.get('event')
if event and grade and (
event.competition.min_years_until_graduation > grade.years_until_graduation
):
raise ValidationError(
f'Ročník {grade.tag} nie je povolený pre {event.competition.name}')
return super().validate(attrs)


@ts_interface(context='competition')
class ProblemCorrectionSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit 0846eaf

Please sign in to comment.