Skip to content

Commit 7179f81

Browse files
committed
Add created_by field to club and team; fix automatically setting primary flag for club member relationship
1 parent f852799 commit 7179f81

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: models.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Club(models.Model):
3434
district = models.ForeignKey('District', related_name='clubs')
3535
members = models.ManyToManyField('Person', related_name='clubs', blank=True, through='ClubMemberRelation')
3636
managers = models.ManyToManyField('Person', blank=True, related_name='clubs_managed', through='ClubManagerRelation')
37+
created_by = models.ForeignKey('Person', blank=True, null=True, related_name='clubs_created')
3738

3839
def __unicode__(self):
3940
return self.name
@@ -47,6 +48,7 @@ class Team(models.Model):
4748
coaches = models.ManyToManyField('Person', blank=True, related_name='teams_coached', through='TeamCoachRelation')
4849
club = models.ForeignKey('Club', related_name='teams')
4950
managers = models.ManyToManyField('Person', blank=True, related_name='teams_managed', through='TeamManagerRelation')
51+
created_by = models.ForeignKey('Person', blank=True, null=True, related_name='teams_created')
5052

5153
def __unicode__(self):
5254
return self.club.name + ' ' + self.name
@@ -266,8 +268,9 @@ def club_member_post_save(sender, instance, created, **kwargs):
266268

267269
# If first club, make primary
268270
clubs = ClubMemberRelation.objects.filter(member=instance.member)
269-
if len(clubs) == 0:
271+
if len(clubs) == 1 and clubs[0].primary == False:
270272
instance.primary = True
273+
instance.save()
271274

272275

273276
def game_post_save(sender, instance, created, **kwargs):

0 commit comments

Comments
 (0)