diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py index ad2b9d5481..0adf7193aa 100644 --- a/akvo/rsr/models/project.py +++ b/akvo/rsr/models/project.py @@ -979,13 +979,13 @@ def budget_total(self): return Project.objects.budget_total().get(pk=self.pk).budget_total def has_multiple_budget_currencies(self): - budget_items = BudgetItem.objects.filter(project__id=self.pk) - num_currencies = len(set([self.currency] + [c.currency if c.currency else self.currency for c in budget_items])) - - if num_currencies > 1: - return True - else: - return False + # Using a python loop for iteration, because it's faster when + # budget_items have been pre-fetched + budget_items = self.budget_items.all() + num_currencies = len( + set([self.currency] + [c.currency for c in budget_items if c.currency]) + ) + return num_currencies > 1 def budget_currency_totals(self): budget_items = BudgetItem.objects.filter(project__id=self.pk) diff --git a/akvo/rsr/views/project.py b/akvo/rsr/views/project.py index 9d3d284777..ea53c61a78 100644 --- a/akvo/rsr/views/project.py +++ b/akvo/rsr/views/project.py @@ -112,7 +112,8 @@ def directory(request): page.object_list = page.object_list.prefetch_related( 'publishingstatus', 'recipient_countries', - 'sectors' + 'sectors', + 'budget_items', ).select_related( 'primary_organisation', 'last_update'