Check that the user is a member of the parent club only at the creation of the membership

This commit is contained in:
Yohann D'ANELLO 2020-08-15 23:52:57 +02:00
parent 4997a37058
commit 9f258e39b6
1 changed files with 2 additions and 1 deletions

View File

@ -384,7 +384,8 @@ class Membership(models.Model):
).exists(): ).exists():
raise ValidationError(_('User is already a member of the club')) 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( if not Membership.objects.filter(
user=self.user, user=self.user,
club=self.club.parent_club, club=self.club.parent_club,