Install django-annoying, which provides some nice shortcuts for common operations

This commit is contained in:
Danielle McLean 2017-10-29 12:41:33 +11:00
parent 88bf1e580c
commit 21786d6e6c
Signed by untrusted user: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
5 changed files with 23 additions and 13 deletions

View file

@ -1,21 +1,21 @@
from django.shortcuts import redirect, render
from annoying.decorators import render_to
from django.shortcuts import redirect
from .models import Entry
@render_to('entries/index.html')
def index(request, kind):
entries = Entry.objects.filter(kind=kind.id)
return render(request, 'entries/index.html', {
'entries': entries,
'title': kind.plural
})
return {'entries': entries, 'title': kind.plural}
@render_to('entries/entry.html')
def entry(request, id, slug=None):
entry = Entry.objects.get(pk=id)
if request.path != entry.url:
return redirect(entry.url, permanent=True)
return render(request, 'entries/entry.html', {
return {
'entry': entry,
'title': entry.title,
'meta': entry.as_meta(request)
})
}