Created
May 7, 2019 06:11
-
-
Save akshar-raaj/0ea1d359c13842a5e947f66172477926 to your computer and use it in GitHub Desktop.
List Questions
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', 'POST']) | |
| def questions_view(request): | |
| if request.method == 'GET': | |
| questions = Question.objects.all() | |
| serializer = QuestionSerializer(questions, many=True) | |
| return Response(serializer.data) | |
| elif request.method == 'POST': | |
| serializer = QuestionSerializer(data=request.data) | |
| if serializer.is_valid(): | |
| question = serializer.save() | |
| return Response("Question created with id %s" % (question.id)) | |
| 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