Animal name is in the URL now.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 5 May 2015 18:19:27 +0000 (20:19 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Tue, 5 May 2015 18:19:27 +0000 (20:19 +0200)
animals/urls.py
animals/views.py

index 8969be55a82d4f8a3e53bb9cb924370b1164a578..9fe80a968e5dcb1f35d14914057ef7d1332b8fad 100644 (file)
@@ -4,5 +4,5 @@ from . import views
 
 urlpatterns = [
     url(r'^$', views.index, name='index'),
 
 urlpatterns = [
     url(r'^$', views.index, name='index'),
-    url(r'^(?P<animal_id>[0-9]+)/$', views.detail),
+    url(r'^(?P<animal_name>\w+)/$', views.detail),
 ]
 ]
index fb5637ea7922929a1c2bb53630cb771e4e3b48c9..48da423e0d44e397e3f49bcfcda1151a5d1022bc 100644 (file)
@@ -7,7 +7,8 @@ def index(request):
     return HttpResponse("Hello, world. You're at the animals index.")
 
 
     return HttpResponse("Hello, world. You're at the animals index.")
 
 
-def detail(request, animal_id):
+def detail(request, animal_name):
     # return HttpResponse("Hello, world. You're at the animal {}.".format(animal_id))
     # return HttpResponse("Hello, world. You're at the animal {}.".format(animal_id))
-    animal = get_object_or_404(Animal, pk=animal_id)
+    animal = get_object_or_404(Animal, name_german=animal_name)
+
     return render(request, 'animals/detail.html', {'animal': animal})
     return render(request, 'animals/detail.html', {'animal': animal})