X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=quotes%2Fviews.py;h=df4081d5b79b251ff5523b98d283dd470b2367d2;hb=ba8a1a46983d9e26f70a6dab5a2a3aa9ebb5425b;hp=91ea44a218fbd2f408430959283f0419c921093e;hpb=e63e884391c4ac2c3af8ff72919a196f7bf9d83f;p=djsite.git diff --git a/quotes/views.py b/quotes/views.py index 91ea44a..df4081d 100644 --- a/quotes/views.py +++ b/quotes/views.py @@ -1,3 +1,35 @@ from django.shortcuts import render +from random import randint + +from .models import Author, Work, 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 work(request, work_id): + work = Work.objects.get(id=work_id) + context = { 'work': work } + return render(request, 'quotes/work.html', context) + +def all(request): + quotes = Quote.objects.all() + context = { 'quotes' : quotes } + return render(request, 'quotes/all.html', context)