]> gitweb.fperrin.net Git - djsite.git/blob - quotes/views.py
bd7f6f605bb142cd44ad196368fa252162dd421c
[djsite.git] / quotes / views.py
1 from django.shortcuts import render
2 from django.http import HttpResponse
3 from django.template import loader
4
5 from random import randint
6
7 from .models import Author, Work, Quote, Tag
8
9 # Create your views here.
10 def onequote(request, quote_id):
11     q = Quote.objects.get(id=quote_id)
12     context = { 'quote' : q }
13     return render(request, 'quotes/onequote.html', context)
14
15 def random(request):
16     count = Quote.objects.count()
17     return onequote(request, randint(1, count))
18
19 def tags(request, tag_id):
20     tag = Tag.objects.get(id=tag_id)
21     context = { 'tag' : tag }
22     return render(request, 'quotes/tag.html', context)
23
24 def author(request, author_id):
25     author = Author.objects.get(id=author_id)
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     context = { 'work': work }
32     return render(request, 'quotes/work.html', context)
33
34 def all(request):
35     quotes = Quote.objects.all()
36     context = { 'quotes' : quotes }
37     return render(request, 'quotes/all.html', context)