Commit 464de9c9 authored by Baptiste Jonglez's avatar Baptiste Jonglez
Browse files

Use aggregation to compute the end date of membership (more efficient)

parent 64ed282f
......@@ -5,7 +5,7 @@ import ldapdb.models
import unicodedata
import datetime
from django.db import models
from django.db.models import Q
from django.db.models import Q, Max
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser
......@@ -107,9 +107,8 @@ class Member(CoinLdapSyncMixin, AbstractUser):
# Renvoie la date de fin de la dernière cotisation du membre
def end_date_of_membership(self):
x = self.membership_fees.order_by('-end_date')
if x:
return self.membership_fees.order_by('-end_date')[0].end_date
aggregate = self.membership_fees.aggregate(end=Max('end_date'))
return aggregate['end']
end_date_of_membership.short_description = "Date de fin d'adhésion"
def is_paid_up(self, date=None):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment