From a4c6e73420a88ca3134eef01b27831da24864407 Mon Sep 17 00:00:00 2001 From: maxime_senza <maxime@happy-dev.fr> Date: Fri, 8 May 2020 16:28:06 +0200 Subject: [PATCH] jb help total votes view --- djangoldp_polls/djangoldp_urls.py | 2 +- djangoldp_polls/views.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/djangoldp_polls/djangoldp_urls.py b/djangoldp_polls/djangoldp_urls.py index d31da44..1157ba4 100644 --- a/djangoldp_polls/djangoldp_urls.py +++ b/djangoldp_polls/djangoldp_urls.py @@ -19,6 +19,6 @@ from django.conf.urls import url from .views import TotalVotes urlpatterns = [ - url(r'votes/(?P<pk>.+)/total_votes/$', TotalVotes.as_view(), name='api-poll-votes'), + url(r'polls/(?P<pk>.+)/total_votes/$', TotalVotes.as_view(), name='api-poll-votes'), ] diff --git a/djangoldp_polls/views.py b/djangoldp_polls/views.py index 52d91f6..d2b10b4 100644 --- a/djangoldp_polls/views.py +++ b/djangoldp_polls/views.py @@ -13,16 +13,16 @@ class FuturePollViewset(LDPViewSet): class TotalVotes(APIView) : def get(self, request, pk): - vote = Vote.objects.get(pk=pk) + poll = Poll.objects.get(pk=pk) # gets all votes for this poll - votes = vote.relatedPoll.votes.all() + votes = poll.votes.all() choices = [] #calcute the number of votes per choice - for choice in vote.chosenOption.userVote.all(): + for choice in poll.pollOptions.all(): #get the number of voter per option and count them - total_votes = votes.filter(userVote=choice).count() + total_votes = votes.filter(chosenOption=choice).count() choices.append((choice.name, total_votes)) # return response with choices in content - return Response() \ No newline at end of file + return Response(choices.total_votes) -- GitLab