1 from django.shortcuts import render, get_object_or_404
2 from poetry.models import Poet, Poem
5 def new(request, slug=None):
7 poet = get_object_or_404(Poet, slug=slug)
9 poet = Poet.objects.order_by('?')[0]
12 return render(request, "poetry/poem.html", locals())
15 def poem(request, slug):
16 poem = get_object_or_404(Poem, slug=slug)
17 return render(request, "poetry/poem.html", locals())
20 def poet(request, slug):
21 poet = get_object_or_404(Poet, slug=slug)
22 last = poet.poem_set.order_by('-created_at')[:20]
23 return render(request, "poetry/poet.html", locals())
27 poets = Poet.objects.all().order_by('?')
28 last = Poem.objects.all().order_by('-created_at')[:20]
29 return render(request, "poetry/main.html", locals())