From eb80169a2bee79283ca0b51fc585ba916755e910 Mon Sep 17 00:00:00 2001 From: chrisjsimpson Date: Wed, 5 Jun 2024 20:40:05 +0100 Subject: [PATCH] Fix #1345 Preserve questions attached to plans upon edit --- subscribie/blueprints/admin/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/subscribie/blueprints/admin/__init__.py b/subscribie/blueprints/admin/__init__.py index f3618733..57ec3c10 100644 --- a/subscribie/blueprints/admin/__init__.py +++ b/subscribie/blueprints/admin/__init__.py @@ -73,6 +73,7 @@ Category, UpcomingInvoice, Document, + PlanQuestionAssociation, ) from .subscription import update_stripe_subscription_statuses from .stats import ( @@ -644,6 +645,16 @@ def edit(): filename = images.save(f) src = url_for("views.custom_static", filename=filename) draftPlan.primary_icon = src + + # Preserve questions + for plan_question_association in plan.questions: + new_plan_question_assoc = PlanQuestionAssociation() + new_plan_question_assoc.question_id = ( + plan_question_association.question_id + ) + new_plan_question_assoc.plan_id = draftPlan.id + database.session.add(new_plan_question_assoc) + database.session.commit() # Save flash("Plan(s) updated.") return redirect(url_for("admin.edit"))