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 in_contest = poet.poem_set.filter(in_contest=True).order_by('created_at')
24 return render(request, "poetry/poet.html", locals())
28 poets = Poet.objects.all().order_by('?')
29 last = Poem.objects.all().order_by('-created_at')[:20]
30 return render(request, "poetry/main.html", locals())
34 poets = Poet.objects.all().order_by('?')
35 return render(request, "poetry/contest.html", locals())