From 9f258e39b6c244ec6edba2dfc75d75bcaf6d0bea Mon Sep 17 00:00:00 2001
From: Yohann D'ANELLO <yohann.danello@gmail.com>
Date: Sat, 15 Aug 2020 23:52:57 +0200
Subject: [PATCH] Check that the user is a member of the parent club only at
 the creation of the membership

---
 apps/member/models.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/apps/member/models.py b/apps/member/models.py
index 86c6fd32..b17f1f09 100644
--- a/apps/member/models.py
+++ b/apps/member/models.py
@@ -384,7 +384,8 @@ class Membership(models.Model):
             ).exists():
                 raise ValidationError(_('User is already a member of the club'))
 
-            if self.club.parent_club is not None:
+            if self.club.parent_club is not None and not self.pk:
+                # Check that the user is already a member of the parent club if the membership is created
                 if not Membership.objects.filter(
                     user=self.user,
                     club=self.club.parent_club,
-- 
GitLab