From ac9de0186bb8d88890fabb7e6bdcddf9516c88d2 Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 8 Feb 2018 07:48:01 +0000
Subject: [PATCH] Only add the extra data when the page is new

---
 opentech/apply/funds/models.py            | 8 +++++---
 opentech/apply/funds/tests/test_models.py | 6 ++++--
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py
index 64d31590a..dea64c76c 100644
--- a/opentech/apply/funds/models.py
+++ b/opentech/apply/funds/models.py
@@ -239,13 +239,15 @@ class Round(SubmittableStreamForm):
         ], heading="Dates"),
     ]
 
-    def create(self, *args, **kwargs):
-        if hasattr(self, 'parent_page'):
+    def save(self, *args, **kwargs):
+        is_new = not self.id
+        if is_new and hasattr(self, 'parent_page'):
             # We attached the parent page as part of the before_create_hook
             self.workflow = self.parent_page.workflow
 
         super().save(*args, **kwargs)
-        if hasattr(self, 'parent_page'):
+
+        if is_new and hasattr(self, 'parent_page'):
             for form in self.parent_page.forms.all():
                 # Create a copy of the existing form object
                 new_form = form.form
diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py
index 946743da4..54a68669a 100644
--- a/opentech/apply/funds/tests/test_models.py
+++ b/opentech/apply/funds/tests/test_models.py
@@ -144,10 +144,12 @@ class TestRoundModelDates(TestCase):
 class TestRoundModelWorkflowAndForms(TestCase):
     def setUp(self):
         self.fund = FundTypeFactory(parent=None)
-        # we only add parent_page on create, so if the object exists already this should not affect testing
-        self.round = RoundFactory()
+
+        self.round = RoundFactory.build()
         self.round.parent_page = self.fund
 
+        self.fund.add_child(instance=self.round)
+
     def test_workflow_is_copied_to_new_rounds(self):
         self.round.save()
         self.assertEqual(self.round.workflow, self.fund.workflow)
-- 
GitLab