Skip to content
Snippets Groups Projects
Commit a4c6e734 authored by maxime_senza's avatar maxime_senza
Browse files

jb help total votes view

parent fe58882f
No related branches found
No related tags found
1 merge request!1Feature : sib polls
Pipeline #5661 failed
......@@ -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'),
]
......@@ -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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment