From 5c0a4ce748661fafce648a8176346ca4e2128eb3 Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Sat, 28 Sep 2019 12:38:57 +0200 Subject: [PATCH] Fix form validation --- preferences/forms.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/preferences/forms.py b/preferences/forms.py index f860640b..312d0b2b 100644 --- a/preferences/forms.py +++ b/preferences/forms.py @@ -300,15 +300,16 @@ class MandateForm(ModelForm): def clean(self): cleaned_data = super(MandateForm, self).clean() start_date, end_date = cleaned_data['start_date'], cleaned_data['end_date'] - included_mandates = Mandate.objects.filter( - Q(start_date__gte=start_date, start_date__lt=end_date) - | Q(end_date__gt=start_date, end_date__lte=end_date) - ) - if included_mandates: - raise forms.ValidationError( - _("The specified dates overlap with an existing mandate."), - code='invalid' + if end_date: + included_mandates = Mandate.objects.filter( + Q(start_date__gte=start_date, start_date__lt=end_date) + | Q(end_date__gt=start_date, end_date__lte=end_date) ) + if included_mandates: + raise forms.ValidationError( + _("The specified dates overlap with an existing mandate."), + code='invalid' + ) return cleaned_data def save(self, commit=True):