From 12ebf9d12affe64b0638c5ad6c71514da5a22488 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 28 Jul 2020 19:38:25 +0200 Subject: [PATCH] Before checking membership roles, we wait before the creation of the membership --- apps/member/models.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/member/models.py b/apps/member/models.py index 0384bf79..e1960a5a 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -302,12 +302,13 @@ class Membership(models.Model): if not Membership.objects.filter(user=self.user, club=self.club.parent_club).exists(): raise ValidationError(_('User is not a member of the parent club') + ' ' + self.club.parent_club.name) - for role in self.roles.all(): - club = role.for_club - if club is not None: - if club.pk != self.club_id: - raise ValidationError(_('The role {role} does not apply to the club {club}.') - .format(role=role.name, club=club.name)) + if self.pk: + for role in self.roles.all(): + club = role.for_club + if club is not None: + if club.pk != self.club_id: + raise ValidationError(_('The role {role} does not apply to the club {club}.') + .format(role=role.name, club=club.name)) created = not self.pk if created: