1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-22 23:42:25 +00:00

[member] Check membership of parent club

This commit is contained in:
Benjamin Graillot 2020-03-25 17:54:28 +01:00
parent a4cb19e5b1
commit c86ddf17ad

View File

@ -4,6 +4,7 @@
import datetime
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
@ -165,6 +166,12 @@ class Membership(models.Model):
else:
return self.date_start.toordinal() <= datetime.datetime.now().toordinal()
def save(self, *args, **kwargs):
if self.club.parent_club is not None:
if not Membership.objects.filter(user=self.user, club=self.club.parent_club):
raise ValidationError(_('User is not a member of the parent club'))
super().save(*args, **kwargs)
class Meta:
verbose_name = _('membership')
verbose_name_plural = _('memberships')