Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Fixed the nutrition plan copy bug

JayanthBonthab76a8b9a4a5a
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}))