mirror of
https://github.com/ae-utbm/sith.git
synced 2024-12-22 15:51:19 +00:00
Add index and query reduction in clubs
This commit is contained in:
parent
2f5bd7d2ef
commit
e689f7f1db
19
club/migrations/0008_auto_20170515_2214.py
Normal file
19
club/migrations/0008_auto_20170515_2214.py
Normal file
@ -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),
|
||||
),
|
||||
]
|
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user