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 415e2d9b6ad11d59dca8cd0154455c969dad1d63..7a0c45ea936429c00b9475a3267c88b5b3a1bf05 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 eacc416ec54f2c73ccf1303be59ea62a5719a191..d182c5a942add4c283e29c0913384163774afcfc 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 = (