diff --git a/apps/contests/models.py b/apps/contests/models.py index c5e8e71..52fceeb 100644 --- a/apps/contests/models.py +++ b/apps/contests/models.py @@ -1,6 +1,5 @@ from typing import Any -from django import forms from django.core.exceptions import ValidationError from django.db.models import ( BooleanField, @@ -8,7 +7,6 @@ DateTimeField, ManyToManyField, ) -from django.utils import timezone from django.utils.timezone import now from apps.contests.enums import ContestStatus @@ -48,22 +46,8 @@ def status(self) -> ContestStatus: else: return ContestStatus.RUNNING + def clean(self) -> Any: + super().clean() -class ContestAdminForm(forms.ModelForm["Contest"]): - def clean_start_time(self) -> Any: - start_time = self.cleaned_data.get("start_time") - if start_time and start_time <= timezone.now(): - raise ValidationError("A data de início deve estar no futuro.") - - return start_time - - def clean_end_time(self) -> Any: - end_time = self.cleaned_data.get("end_time") - start_time = self.cleaned_data.get("start_time") - - if end_time and end_time <= start_time: - raise ValidationError( - "A data de término deve ser posterior a data de início." - ) - - return end_time + if self.start_time > self.end_time: + raise ValidationError("Start time must be before end time.")