From 7ad843c1ebaa421da33dcf9ffb2dcd5006bd6722 Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Sun, 7 Oct 2018 20:12:32 +0200 Subject: [PATCH] Update query --- organizations/models.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/organizations/models.py b/organizations/models.py index 494566cd2..5a1f335dc 100644 --- a/organizations/models.py +++ b/organizations/models.py @@ -148,11 +148,7 @@ class Organization(models.Model): Computes the total amount received by SciPost, in the form of subsidies from this Organization. """ - contrib = 0 - now = timezone.now().date() - for subsidy in self.subsidy_set.all(): - contrib += subsidy.amount - return contrib + return self.subsidy_set.aggregate(models.Sum('amount')).get('amount__sum', 0) def get_total_contribution_obtained(self, n_years_past=None): """ @@ -160,7 +156,6 @@ class Organization(models.Model): summed over all time. """ contrib = 0 - now = timezone.now().date() for agreement in self.partner.agreements.all(): - contrib += agreement.offered_yearly_contribution * int(agreement.duration.days/365) + contrib += agreement.offered_yearly_contribution * int(agreement.duration.days / 365) return contrib -- GitLab