|
@@ -41,7 +41,6 @@ def index(request):
|
|
|
|
|
|
# Check if voter has already voted on this question
|
|
# Check if voter has already voted on this question
|
|
for question in questions:
|
|
for question in questions:
|
|
- print(question)
|
|
|
|
voter_question = VoterQuestion.objects.filter(voter=voter, question=question).first()
|
|
voter_question = VoterQuestion.objects.filter(voter=voter, question=question).first()
|
|
if voter_question is None:
|
|
if voter_question is None:
|
|
# Add the voter to the VoterQuestion table
|
|
# Add the voter to the VoterQuestion table
|
|
@@ -53,7 +52,7 @@ def index(request):
|
|
vote.save()
|
|
vote.save()
|
|
|
|
|
|
# Redirect to the results page
|
|
# Redirect to the results page
|
|
- return render(request, 'vote/results.html')
|
|
|
|
|
|
+ return render(request, 'vote/thankyou.html')
|
|
|
|
|
|
questions = Question.objects.all()
|
|
questions = Question.objects.all()
|
|
|
|
|
|
@@ -63,3 +62,21 @@ def index(request):
|
|
}
|
|
}
|
|
|
|
|
|
return render(request, 'vote/index.html', context=context)
|
|
return render(request, 'vote/index.html', context=context)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def results(request):
|
|
|
|
+
|
|
|
|
+ # Tally the votes for each question
|
|
|
|
+ questions = Question.objects.all()
|
|
|
|
+ for question in questions:
|
|
|
|
+ yes_votes = Vote.objects.filter(question=question, vote=True).count()
|
|
|
|
+ no_votes = Vote.objects.filter(question=question, vote=False).count()
|
|
|
|
+ question.total_votes = yes_votes + no_votes
|
|
|
|
+ question.yes_votes = yes_votes
|
|
|
|
+ question.no_votes = no_votes
|
|
|
|
+
|
|
|
|
+ context = {
|
|
|
|
+ 'questions': questions,
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return render(request, 'vote/results.html', context=context)
|