From 73c8673e92a175de5247ed52bcb76eb6eb3b8a95 Mon Sep 17 00:00:00 2001 From: ergz Date: Sat, 23 Jul 2022 23:38:12 -0700 Subject: [PATCH] adds a results template --- db.sqlite3 | Bin 143360 -> 143360 bytes polls/templates/polls/results.html | 9 +++++++++ polls/views.py | 8 +++++--- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 polls/templates/polls/results.html diff --git a/db.sqlite3 b/db.sqlite3 index 2170b7ef8772024380e0bee9da07b505673dd02e..7e70edbe9734118f8a641e9888a1081e99e4ffdd 100644 GIT binary patch delta 128 zcmZp8z|ru4V}dlJ%|sbzMw`Zj)&$0_2~5lQS^63H`?qrmFtzeK@iMY9NHcQg<(Fh+ z=B2anu(L9VGcu+Zr6!gzGjX!9G6-`pCMBjYaj~*8h;lNfW#*+a@qc3A;N@Us5@%** gFyx$mQJzVHmy@$3BUPa|yOM!{fp7aac_uCa0K32&=Kufz delta 116 zcmZp8z|ru4V}dlJ=|mZ4M$^WG)&$0_2~5lQS>`eDf7;F^z|_h=F@WEghn`ER+R)+20{{ question.question_text }} + +
    +{% for choice in question.choice_set.all %} +
  • {{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}
  • +{% endfor %} +
+ +Vote again? \ No newline at end of file diff --git a/polls/views.py b/polls/views.py index c981dc1..d9742f1 100644 --- a/polls/views.py +++ b/polls/views.py @@ -20,9 +20,10 @@ def detail(request, question_id): return render(request, "polls/details.html", {"question": question}) + def results(request, question_id): - response = "you are looking at results for question %s" - return HttpResponse(response % question_id) + question = get_object_or_404(Question, pk=question_id) + return render(request, 'polls/results.html', {'question': question}) def vote(request, question_id): question = get_object_or_404(Question, pk=question_id) @@ -37,4 +38,5 @@ def vote(request, question_id): selected_choice.votes += 1 selected_choice.save() - return HttpResponseRedirect(reverse("polls:results", args=(question.id,))) \ No newline at end of file + return HttpResponseRedirect(reverse("polls:results", args=(question.id,))) +