From 4120d0230b79bcda7b2fdf58fbb886ae209f55df Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 16 Nov 2023 14:17:19 +0100 Subject: [PATCH] fix dates with end_date empty --- idhub/admin/forms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 90a9c0c..a219a0f 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -148,6 +148,10 @@ class MembershipForm(forms.ModelForm): if self.instance.id: members = members.exclude(id=self.instance.id) + if members.filter(start_date__lte=start_date, end_date=None).exists(): + msg = _("This membership already exists!") + raise forms.ValidationError(msg) + if (start_date and end_date): if start_date > end_date: msg = _("The end date is less than the start date") @@ -161,6 +165,16 @@ class MembershipForm(forms.ModelForm): if members.exists(): msg = _("This membership already exists!") raise forms.ValidationError(msg) + + if not end_date: + members = members.filter( + start_date__gte=start_date, + ) + + if members.exists(): + msg = _("This membership already exists!") + raise forms.ValidationError(msg) + return end_date