X-Git-Url: http://gitweb.fperrin.net/?p=djsite.git;a=blobdiff_plain;f=quotes%2Fviews.py;h=615719209327f58096622d8b3d5e8b51d3928c98;hp=91ea44a218fbd2f408430959283f0419c921093e;hb=45be55604156dc0064aa32ea508df0d90ac5a17a;hpb=e63e884391c4ac2c3af8ff72919a196f7bf9d83f diff --git a/quotes/views.py b/quotes/views.py index 91ea44a..6157192 100644 --- a/quotes/views.py +++ b/quotes/views.py @@ -1,3 +1,32 @@ from django.shortcuts import render +from django.http import HttpResponse +from django.template import loader + +from random import randint + +from .models import Author, Quote, Tag # Create your views here. +def onequote(request, quote_id): + q = Quote.objects.get(id=quote_id) + context = { 'quote' : q } + return render(request, 'quotations/onequote.html', context) + +def random(request): + count = Quote.objects.count() + return onequote(request, randint(1, count)) + +def tags(request, tag_id): + tag = Tag.objects.get(id=tag_id) + context = { 'tag' : tag } + return render(request, 'quotations/tag.html', context) + +def author(request, author_id): + author = Author.objects.get(id=author_id) + context = { 'author' : author } + return render(request, 'quotations/author.html', context) + +def all(request): + quotes = Quote.objects.all() + context = { 'quotes' : quotes } + return render(request, 'quotations/all.html', context)