def question_create(request): if request.method == 'POST': data = JSONParser().parse(request) serializer = QuestionSerializer(data=data, context={'request': request}) if serializer.is_valid(): new_question = serializer.save() target_from_question(new_question) get_news_for_question(new_question) return JSONResponse(add_user(serializer.data, request)) return JSONResponse(serializer.errors, status=400)
def question_update(request, pk): try: question = Question.objects.get(pk=pk) except Question.DoesNotExist: return HttpResponse(status=404) if request.method == 'POST': data = JSONParser().parse(request) serializer = QuestionSerializer(question, data=data, partial=True, context={'request': request}) if serializer.is_valid(): serializer.save() return JSONResponse(add_user(serializer.data, request)) return JSONResponse(serializer.errors, status=400)