diff --git a/club/migrations/0008_auto_20170515_2214.py b/club/migrations/0008_auto_20170515_2214.py new file mode 100644 index 00000000..48f5b3b6 --- /dev/null +++ b/club/migrations/0008_auto_20170515_2214.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('club', '0007_auto_20170324_0917'), + ] + + operations = [ + migrations.AlterField( + model_name='club', + name='id', + field=models.AutoField(primary_key=True, serialize=False, db_index=True), + ), + ] diff --git a/club/models.py b/club/models.py index 587dd56c..4f1f4852 100644 --- a/club/models.py +++ b/club/models.py @@ -39,6 +39,7 @@ class Club(models.Model): """ The Club class, made as a tree to allow nice tidy organization """ + id = models.AutoField(primary_key=True, db_index=True) name = models.CharField(_('name'), max_length=64) parent = models.ForeignKey('Club', related_name='children', null=True, blank=True) unix_name = models.CharField(_('unix name'), max_length=30, unique=True, @@ -151,11 +152,21 @@ class Club(models.Model): return False return sub.is_subscribed + _memberships = {} def get_membership_for(self, user): """ Returns the current membership the given user """ - return self.members.filter(user=user.id).filter(end_date=None).first() + try: + return Club._memberships[self.id][user.id] + except: + m = self.members.filter(user=user.id).filter(end_date=None).first() + try: + Club._memberships[self.id][user.id] = m + except: + Club._memberships[self.id] = {} + Club._memberships[self.id][user.id] = m + return m class Membership(models.Model): """