From 275636447b2d55b0fb666f808f6e5ff92aae43fd Mon Sep 17 00:00:00 2001 From: JayanthBontha Date: Thu, 12 Oct 2023 23:58:53 +0530 Subject: [PATCH 1/2] modified: wger/nutrition/views/plan.py --- wger/nutrition/views/plan.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py index cae8300ca..b3b4fab15 100644 --- a/wger/nutrition/views/plan.py +++ b/wger/nutrition/views/plan.py @@ -202,19 +202,19 @@ def copy(request, pk): """ Copy the nutrition plan """ - + logger.debug(request.user) plan = get_object_or_404(NutritionPlan, pk=pk, user=request.user) # Copy plan - meals = plan.meal_set.all() + meals = plan.meal_set.select_related() plan_copy = plan plan_copy.pk = None plan_copy.save() - + # Copy the meals for meal in meals: - meal_items = meal.mealitem_set.all() + meal_items = meal.mealitem_set.select_related() meal_copy = meal meal_copy.pk = None @@ -226,7 +226,7 @@ def copy(request, pk): item_copy = item item_copy.pk = None item_copy.meal = meal_copy - item.save() + item_copy.save() # Redirect return HttpResponseRedirect(reverse('nutrition:plan:view', kwargs={'id': plan.id})) From c2316cf959c8cb54c7115776872a68e258558678 Mon Sep 17 00:00:00 2001 From: JayanthBontha Date: Fri, 13 Oct 2023 00:16:19 +0530 Subject: [PATCH 2/2] Fixed Copy of NutritionPlan --- wger/nutrition/views/plan.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py index b3b4fab15..6b7659f73 100644 --- a/wger/nutrition/views/plan.py +++ b/wger/nutrition/views/plan.py @@ -202,7 +202,6 @@ def copy(request, pk): """ Copy the nutrition plan """ - logger.debug(request.user) plan = get_object_or_404(NutritionPlan, pk=pk, user=request.user) # Copy plan @@ -211,7 +210,6 @@ def copy(request, pk): plan_copy = plan plan_copy.pk = None plan_copy.save() - # Copy the meals for meal in meals: meal_items = meal.mealitem_set.select_related()