From 09e61e917b545fa8c39105285d4b82e95307151c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Perrin?= Date: Fri, 11 Nov 2016 10:20:51 +0000 Subject: [PATCH] Fix the random page to not assume 1-based, no gap indexes --- quotes/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/quotes/views.py b/quotes/views.py index d6ca240..642cb43 100644 --- a/quotes/views.py +++ b/quotes/views.py @@ -12,13 +12,17 @@ def index(request): def onequote(request, quote_id): q = Quote.objects.get(id=quote_id) - q.incr_display() - context = { 'quote' : q } - return render(request, 'quotes/onequote.html', context) + return _onequote(request, q) def random(request): count = Quote.objects.count() - return onequote(request, randint(1, count)) + q = Quote.objects.all()[randint(0, count-1)] + return _onequote(request, q) + +def _onequote(request, q): + q.incr_display() + context = { 'quote' : q } + return render(request, 'quotes/onequote.html', context) def tags(request, tag_id): tag = QuoteTag.objects.get(id=tag_id) -- 2.43.0