X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Fviews.py;h=981af054515b7817efb40daae2138b7d34de0b1a;hb=979f7e231fdda726b78bb00914d4a5e22a1d81b7;hp=91ea44a218fbd2f408430959283f0419c921093e;hpb=e63e884391c4ac2c3af8ff72919a196f7bf9d83f;p=djsite.git diff --git a/quotes/views.py b/quotes/views.py index 91ea44a..981af05 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, 'quotes/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, 'quotes/tag.html', context) + +def author(request, author_id): + author = Author.objects.get(id=author_id) + context = { 'author' : author } + return render(request, 'quotes/author.html', context) + +def all(request): + quotes = Quote.objects.all() + context = { 'quotes' : quotes } + return render(request, 'quotes/all.html', context)