mirror of https://gitlab.crans.org/bde/nk20
[member] Check membership of parent club
This commit is contained in:
parent
a4cb19e5b1
commit
c86ddf17ad
|
@ -4,6 +4,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse, reverse_lazy
|
from django.urls import reverse, reverse_lazy
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
@ -165,6 +166,12 @@ class Membership(models.Model):
|
||||||
else:
|
else:
|
||||||
return self.date_start.toordinal() <= datetime.datetime.now().toordinal()
|
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:
|
class Meta:
|
||||||
verbose_name = _('membership')
|
verbose_name = _('membership')
|
||||||
verbose_name_plural = _('memberships')
|
verbose_name_plural = _('memberships')
|
||||||
|
|
Loading…
Reference in New Issue