Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add a slug to the ingredient URLs as with exercises
Roland Geider57c2fcf9ba9c
diff --git a/nutrition/models.py b/nutrition/models.pyindex 5d5a5768d..adf0fb8fa 100644--- a/nutrition/models.py+++ b/nutrition/models.py@@ -18,6 +18,7 @@from django.db import models+from django.template.defaultfilters import slugify # django.utils.text.slugify in django 1.5!from django.core.validators import MaxValueValidatorfrom django.core.urlresolvers import reversefrom django.contrib.auth.models import User@@ -147,7 +148,8 @@ class Ingredient(models.Model):"""Returns the canonical URL to view this object"""- return reverse('nutrition.views.ingredient_view', kwargs={'id': self.id})+ return reverse('nutrition.views.ingredient_view', kwargs={'id': self.id,+ 'slug': slugify(self.name)})def __unicode__(self):"""Return a more human-readable representationdiff --git a/nutrition/urls.py b/nutrition/urls.pyindex 6d74d8510..33eeb1b41 100644--- a/nutrition/urls.py+++ b/nutrition/urls.py@@ -17,6 +17,7 @@ urlpatterns = patterns('nutrition.views',# Plansurl(r'^add/$', 'add'),url(r'^(?P<id>\d+)/view/$', 'view'),+url(r'^(?P<pk>\d+)/copy/$','copy',name='nutrition-copy'),@@ -58,5 +59,6 @@ urlpatterns = patterns('nutrition.views',url(r'^ingredient/overview/$', 'ingredient_overview'),url(r'^ingredient/(?P<id>\d+)/view/$', 'ingredient_view'),+ url(r'^ingredient/(?P<id>\d+)/view/(?P<slug>[-\w]+)/$', 'ingredient_view'),url(r'^ingredient/search/$', 'ingredient_search'),)diff --git a/nutrition/views.py b/nutrition/views.pyindex cc9cf2fee..f65ac93c1 100644--- a/nutrition/views.py+++ b/nutrition/views.py@@ -478,7 +478,7 @@ def ingredient_overview(request):context_instance=RequestContext(request))-def ingredient_view(request, id):+def ingredient_view(request, id, slug=None):template_data = {}ingredient = get_object_or_404(Ingredient, pk=id)