]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/views.py
Use django-tagging for tags
[djsite.git] / quotes / views.py
index 91ea44a218fbd2f408430959283f0419c921093e..002c4e34a6b8ada081f5ffcd0ffab4663c204d7a 100644 (file)
@@ -1,3 +1,35 @@
 from django.shortcuts import render
 
+from random import randint
+
+from .models import Author, Work, Quote
+
 # 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)