Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy plan fix #1460

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions wger/nutrition/views/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,17 @@ def copy(request, pk):
"""
Copy the nutrition plan
"""

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 @@ -226,7 +224,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