From 6764b6a03490842df9d40a4d9708d8833df292f7 Mon Sep 17 00:00:00 2001 From: Ramon Ramos Date: Wed, 11 Sep 2024 14:15:24 -0600 Subject: [PATCH] Streamline migration to use existing record instead of deleting and creating --- .../0162_remove_focusarea_page_and_more.py | 13 ++++++++++--- .../wagtailpages/fragments/focus_area.html | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/network-api/networkapi/wagtailpages/migrations/0162_remove_focusarea_page_and_more.py b/network-api/networkapi/wagtailpages/migrations/0162_remove_focusarea_page_and_more.py index 084d834656..c6e549922d 100644 --- a/network-api/networkapi/wagtailpages/migrations/0162_remove_focusarea_page_and_more.py +++ b/network-api/networkapi/wagtailpages/migrations/0162_remove_focusarea_page_and_more.py @@ -26,9 +26,16 @@ def update_focus_areas_and_add_hero_bottom(apps, schema_editor): }, ] - FocusArea.objects.all().delete() - for area in focus_areas: - FocusArea.objects.create(**area) + existing_focus_areas = list(FocusArea.objects.all()) + + for index, data in enumerate(focus_areas): + if index < len(existing_focus_areas): + focus_area = existing_focus_areas[index] + focus_area.name = data['name'] + focus_area.description = data['description'] + focus_area.save() + else: + FocusArea.objects.create(**data) # Add hero_bottom data to Homepage homepage = Homepage.objects.first() diff --git a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/focus_area.html b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/focus_area.html index 942448a988..22c233d10a 100644 --- a/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/focus_area.html +++ b/network-api/networkapi/wagtailpages/templates/wagtailpages/fragments/focus_area.html @@ -4,7 +4,7 @@ {% image area.interest_icon width-100 class="tw-max-w-[4em] tw-max-h-[4em]" alt=area.interest_icon.title %}
-

{{ area.name }}

+

{{ area.name }}

{{ area.description }}