Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add function to delete nutritional plans
Roland Geider9a1514a801c7
diff --git a/nutrition/templates/view_nutrition_plan.html b/nutrition/templates/view_nutrition_plan.htmlindex 21dc75554..91684e41f 100644--- a/nutrition/templates/view_nutrition_plan.html+++ b/nutrition/templates/view_nutrition_plan.html@@ -222,6 +222,16 @@ $(document).ready(function() {</a></p>+<p>+<a href="{% url nutrition.views.delete_plan plan.id %}">+ <img src="{% static 'images/icons/trash.svg' %}"+ width="32"+ height="32"+ alt="{% trans 'Delete nutrition plan' %}">+ {% trans "Delete nutrition plan" %}+</a>+</p>+<p><a href="{% url nutrition.views.ingredient_overview %}"><img src="{% static 'images/icons/list.svg' %}"diff --git a/nutrition/urls.py b/nutrition/urls.pyindex 6e7304063..5af63a212 100644--- a/nutrition/urls.py+++ b/nutrition/urls.py@@ -5,8 +5,9 @@ urlpatterns = patterns('nutrition.views',# Plansurl(r'^nutrition/add/$', 'add'),- url(r'^nutrition/(?P<id>\d+)/view/$', 'view'),- url(r'^nutrition/(?P<id>\d+)/edit/plan/$', 'edit_plan'),+ url(r'^nutrition/(?P<id>\d+)/view/$', 'view'),+ url(r'^nutrition/(?P<id>\d+)/delete/$', 'delete_plan'),+ url(r'^nutrition/(?P<id>\d+)/edit/$', 'edit_plan'),# Mealsurl(r'^nutrition/(?P<id>\d+)/edit/meal/(?P<meal_id>\w*)$', 'edit_meal'),diff --git a/nutrition/views.py b/nutrition/views.pyindex 11aab925e..eb7a3e5be 100644--- a/nutrition/views.py+++ b/nutrition/views.py@@ -75,6 +75,16 @@ def add(request):return HttpResponseRedirect('/nutrition/%s/view/' % plan.id)+@login_required+def delete_plan(request, id):+ """Deletes the nutritional plan with the given ID+ """++ # Load the plan+ plan = get_object_or_404(NutritionPlan, pk=id, user=request.user)+ plan.delete()++ return HttpResponseRedirect('/')@login_requireddef view(request, id):