diff options
author | Matthew Lemon <y@yulqen.org> | 2024-09-09 14:55:38 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-09-09 14:55:38 +0100 |
commit | 09b099e467df64ac8ce44bbe2d1f80cd1c00a126 (patch) | |
tree | b4f4110337cde4d0586c3152d42ce9b5133faf53 /engagements/forms.py | |
parent | e57e4a03bbe67d3801656ceb5c2f8249dba6456d (diff) |
Basic validation on start and end dates for Engagement
- form validation when end date is before the start date
Diffstat (limited to 'engagements/forms.py')
-rw-r--r-- | engagements/forms.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/engagements/forms.py b/engagements/forms.py index 2532892..0b097df 100644 --- a/engagements/forms.py +++ b/engagements/forms.py @@ -1,5 +1,6 @@ from django import forms from django.forms.widgets import HiddenInput +from django.core.exceptions import ValidationError from .models import Engagement, EngagementEffort @@ -187,6 +188,16 @@ class EngagementCreateForm(forms.ModelForm): except KeyError: pass + def clean_proposed_end_date(self): + proposed_start_date = self.cleaned_data["proposed_start_date"] + proposed_end_date = self.cleaned_data["proposed_end_date"] + + if proposed_start_date and proposed_end_date: + if proposed_start_date > proposed_end_date: + raise ValidationError("The proposed start date must be before the proposed end date.") + + return proposed_start_date + class Meta: model = Engagement fields = [ |