Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save akshar-raaj/31d4feb76ecfcea99c938665defa9530 to your computer and use it in GitHub Desktop.
Choices View
@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