Created
May 7, 2019 10:17
-
-
Save akshar-raaj/f8bdf8a96de65570394dde576fd4580a to your computer and use it in GitHub Desktop.
Question Patch
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(['GET', 'PATCH', 'DELETE']) | |
| def question_detail_view(request, question_id): | |
| question = get_object_or_404(Question, pk=question_id) | |
| if request.method == 'GET': | |
| serializer = QuestionSerializer(question) | |
| return Response(serializer.data) | |
| elif request.method == 'PATCH': | |
| serializer = QuestionSerializer(question, data=request.data, partial=True) | |
| if serializer.is_valid(): | |
| question = serializer.save() | |
| serializer = QuestionSerializer(question) | |
| return Response(serializer.data) | |
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | |
| elif request.method == 'DELETE': | |
| raise NotImplementedError("DELETE currently not supported") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment