From 6de415fa49e508a0dc14937f418b0bde23c2dc57 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Fri, 31 Aug 2018 20:22:29 +0100
Subject: [PATCH] Remove the duplicate projects from the funds listingn

---
 .../templates/public_funds/blocks/related_projects.html    | 4 ++--
 opentech/public/projects/models.py                         | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/opentech/public/funds/templates/public_funds/blocks/related_projects.html b/opentech/public/funds/templates/public_funds/blocks/related_projects.html
index 415e2d9b6..7a0c45ea9 100644
--- a/opentech/public/funds/templates/public_funds/blocks/related_projects.html
+++ b/opentech/public/funds/templates/public_funds/blocks/related_projects.html
@@ -1,8 +1,8 @@
-{% if page.projectfunding_set.all %}
+{% if page.projectfunding_set.unique %}
     <div class="wrapper wrapper--breakout">
         <div class="wrapper--media-boxes">
             <div class="grid grid--two grid--medium-gap">
-                {% for funding in page.projectfunding_set.all %}
+                {% for funding in page.projectfunding_set.unique %}
                     {% include "public_funds/includes/project_listing.html" with project=funding.page %}
                 {% endfor %}
             </div>
diff --git a/opentech/public/projects/models.py b/opentech/public/projects/models.py
index eacc416ec..d182c5a94 100644
--- a/opentech/public/projects/models.py
+++ b/opentech/public/projects/models.py
@@ -84,9 +84,16 @@ class ProjectPageRelatedPage(RelatedPage):
     ]
 
 
+class ProjectFundingQueryset(models.QuerySet):
+    def unique(self):
+        return self.order_by().distinct('page')
+
+
 class ProjectFunding(BaseFunding):
     page = ParentalKey('ProjectPage', related_name='funding')
 
+    objects = ProjectFundingQueryset.as_manager()
+
 
 class ProjectPage(FundingMixin, BasePage):
     STATUSES = (
-- 
GitLab