Skip to content

Commit

Permalink
Merge pull request #1467 from JayanthBontha/CopyPlanFix
Browse files Browse the repository at this point in the history
Fixed the nutrition plan copy bug
  • Loading branch information
rolandgeider authored Oct 17, 2023
2 parents 427bce7 + b76a8b9 commit 7c2e398
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wger/nutrition/views/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ 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
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
Expand All @@ -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}))
Expand Down

0 comments on commit 7c2e398

Please sign in to comment.