Created
May 7, 2019 11:07
-
-
Save akshar-raaj/ca4c8956b52a906bf49afd0227f83848 to your computer and use it in GitHub Desktop.
Vote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @api_view(['PATCH']) | |
| def vote_view(request, question_id): | |
| question = get_object_or_404(Question, pk=question_id) | |
| serializer = VoteSerializer(data=request.data) | |
| if serializer.is_valid(): | |
| choice = get_object_or_404(Choice, pk=serializer.validated_data['choice_id'], question=question) | |
| choice.votes += 1 | |
| choice.save() | |
| return Response("Voted") | |
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment