From 84de02a841c8772dc4e5d03d5cc73f724b3dd840 Mon Sep 17 00:00:00 2001 From: Mateus de Morais Date: Fri, 27 Apr 2018 18:29:52 -0300 Subject: [PATCH] Fix #58 --- api/views.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/api/views.py b/api/views.py index b200357..ebdd638 100644 --- a/api/views.py +++ b/api/views.py @@ -568,13 +568,26 @@ def get_queryset(self): return queryset def list(self, request): - return super(UserVoteViewset, self).list(request) + response = super(UserVoteViewset, self).list(request) + + for vote in response.data['results']: + proposition = Proposition.objects.get(pk=vote['proposition']) + proposition_serializer = PropositionSerializer(proposition) + vote['proposition'] = proposition_serializer.data + + return response def create(self, request): user_id = request.user.id request.data['user'] = user_id - return super(UserVoteViewset, self).create(request) + response = super(UserVoteViewset, self).create(request) + + proposition = Proposition.objects.get(pk=response.data['proposition']) + proposition_serializer = PropositionSerializer(proposition) + response.data['proposition'] = proposition_serializer.data + + return response def destroy(self, request, pk=None): response = super(UserVoteViewset, self).destroy(request, pk) @@ -582,6 +595,11 @@ def destroy(self, request, pk=None): def retrieve(self, request, pk=None): response = super(UserVoteViewset, self).retrieve(request, pk) + + proposition = Proposition.objects.get(pk=response.data['proposition']) + proposition_serializer = PropositionSerializer(proposition) + response.data['proposition'] = proposition_serializer.data + return response def partial_update(self, request, pk=None, **kwargs): @@ -602,6 +620,11 @@ def update(self, request, pk=None, **kwargs): request, pk, **kwargs) + + proposition = Proposition.objects.get(pk=response.data['proposition']) + proposition_serializer = PropositionSerializer(proposition) + response.data['proposition'] = proposition_serializer.data + return response