From 9646fa9eaa27fd0de5787e1d31c0fcc97e7a6c21 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 24 Jan 2018 10:53:24 +0000 Subject: [PATCH] Provide the parent page of the round on the object before the save --- opentech/apply/funds/models.py | 2 +- opentech/apply/funds/wagtail_hooks.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 224563277..c585cd9c7 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -143,7 +143,7 @@ class Round(AbstractStreamForm): Q(end_date__gte=self.start_date) ) - conflicting_rounds = Round.objects.sibling_of(self).filter( + conflicting_rounds = Round.objects.child_of(self.parent_page).filter( conflict_query ).exclude(id=self.id) diff --git a/opentech/apply/funds/wagtail_hooks.py b/opentech/apply/funds/wagtail_hooks.py index d9ad3c978..178e17a66 100644 --- a/opentech/apply/funds/wagtail_hooks.py +++ b/opentech/apply/funds/wagtail_hooks.py @@ -1,6 +1,15 @@ +from wagtail.wagtailcore import hooks from wagtail.contrib.modeladmin.options import modeladmin_register from .admin import ApplyAdminGroup +from .models import Round modeladmin_register(ApplyAdminGroup) + + +@hooks.register('before_create_page') +def before_create_page(request, parent_page, page_class): + if page_class == Round: + page_class.parent_page = parent_page + return page_class -- GitLab