From b76a8b9a4a5ae5a553485b4d4ad097f47d8796cf Mon Sep 17 00:00:00 2001 From: JayanthBontha Date: Tue, 17 Oct 2023 15:14:01 +0530 Subject: [PATCH] Fixed the nutrition plan copy bug --- wger/nutrition/views/plan.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py index f2e20f261..94cdfe4d0 100644 --- a/wger/nutrition/views/plan.py +++ b/wger/nutrition/views/plan.py @@ -68,7 +68,7 @@ def copy(request, pk): 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 @@ -76,7 +76,7 @@ def copy(request, pk): # 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 @@ -88,7 +88,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}))