]> gitweb.fperrin.net Git - djsite.git/blob - quotes/views.py
Add a simple display counter
[djsite.git] / quotes / views.py
1 from django.shortcuts import render
2
3 from random import randint
4
5 from .models import Author, Work, Quote, QuoteTag
6
7 # Create your views here.
8 def onequote(request, quote_id):
9     q = Quote.objects.get(id=quote_id)
10     q.incr_display()
11     context = { 'quote' : q }
12     return render(request, 'quotes/onequote.html', context)
13
14 def random(request):
15     count = Quote.objects.count()
16     return onequote(request, randint(1, count))
17
18 def tags(request, tag_id):
19     tag = QuoteTag.objects.get(id=tag_id)
20     context = { 'tag' : tag }
21     return render(request, 'quotes/tag.html', context)
22
23 def author(request, author_id):
24     author = Author.objects.get(id=author_id)
25     author.incr_display()
26     context = { 'author' : author }
27     return render(request, 'quotes/author.html', context)
28
29 def work(request, work_id):
30     work = Work.objects.get(id=work_id)
31     work.incr_display()
32     context = { 'work': work }
33     return render(request, 'quotes/work.html', context)
34
35 def all(request):
36     quotes = Quote.objects.all()
37     context = { 'quotes' : quotes }
38     return render(request, 'quotes/all.html', context)