Created
May 7, 2019 10:26
-
-
Save akshar-raaj/31d4feb76ecfcea99c938665defa9530 to your computer and use it in GitHub Desktop.
Choices View
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(['POST']) | |
| def choices_view(request, question_id): | |
| question = get_object_or_404(Question, pk=question_id) | |
| serializer = ChoiceSerializer(data=request.data) | |
| if serializer.is_valid(): | |
| choice = serializer.save(question=question) | |
| return Response("Choice created with id %s" % (choice.id), status=status.HTTP_201_CREATED) | |
| 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