Skip to content
Snippets Groups Projects
Commit e27b456a authored by Pierre-antoine Comby's avatar Pierre-antoine Comby
Browse files

Merge branch 'parent-club' into 'master'

Resolve "Club Parent"

Closes #42

See merge request !65
parents e8cbd463 59cd166b
No related branches found
No related tags found
1 merge request!65Resolve "Club Parent"
Pipeline #8049 passed with warnings with stages
in 3 minutes and 38 seconds
......@@ -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 _
......@@ -67,6 +68,13 @@ class Club(models.Model):
email = models.EmailField(
verbose_name=_('email'),
)
parent_club = models.ForeignKey(
'self',
null=True,
blank=True,
on_delete=models.PROTECT,
verbose_name=_('parent club'),
)
# Memberships
membership_fee = models.PositiveIntegerField(
......@@ -158,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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment