Merge branch 'parent-club' into 'master'

Resolve "Club Parent"

Closes #42

See merge request bde/nk20!65
This commit is contained in:
Pierre-antoine Comby 2020-03-27 13:29:43 +01:00
commit e27b456aea
1 changed files with 14 additions and 0 deletions

View File

@ -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 _
@ -67,6 +68,13 @@ class Club(models.Model):
email = models.EmailField( email = models.EmailField(
verbose_name=_('email'), verbose_name=_('email'),
) )
parent_club = models.ForeignKey(
'self',
null=True,
blank=True,
on_delete=models.PROTECT,
verbose_name=_('parent club'),
)
# Memberships # Memberships
membership_fee = models.PositiveIntegerField( membership_fee = models.PositiveIntegerField(
@ -158,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')