Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created May 7, 2019 10:17
Show Gist options
  • Select an option

  • Save akshar-raaj/f8bdf8a96de65570394dde576fd4580a to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/f8bdf8a96de65570394dde576fd4580a to your computer and use it in GitHub Desktop.
Question Patch
@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