from django.conf.urls import include, url
from django.contrib import admin
+
urlpatterns = [
# Examples:
# url(r'^$', 'alpenzoo_django.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
+ url(r'^animals/', include('animals.urls')),
url(r'^admin/', include(admin.site.urls)),
]
from django.contrib import admin
+from .models import Animal
+
+
+class AnimalAdmin(admin.ModelAdmin):
+ list_display = ('name_german', 'size_cm')
+
# Register your models here.
+admin.site.register(Animal, AnimalAdmin)
\ No newline at end of file
size_cm = models.IntegerField()
edible = models.BooleanField()
+ def __str__(self):
+ return self.name_german
+
--- /dev/null
+<h1>{{ animal.name_german }}</h1>
+<ul>
+ <li>Size: {{ animal.size_cm }}</li>
+</ul>
\ No newline at end of file
--- /dev/null
+from django.conf.urls import url
+
+from . import views
+
+urlpatterns = [
+ url(r'^$', views.index, name='index'),
+ url(r'^(?P<animal_id>[0-9]+)/$', views.detail),
+]
-from django.shortcuts import render
+from django.shortcuts import get_object_or_404, render
+from django.http import HttpResponse
+from .models import Animal
# Create your views here.
+def index(request):
+ return HttpResponse("Hello, world. You're at the animals index.")
+
+
+def detail(request, animal_id):
+ # return HttpResponse("Hello, world. You're at the animal {}.".format(animal_id))
+ animal = get_object_or_404(Animal, pk=animal_id)
+ return render(request, 'animals/detail.html', {'animal': animal})