def add_answer(request, user_id, question_id): mentor = Mentor.objects.get(id=user_id) question = Question.objects.get(id=question_id) answer = Answer() answer.author = mentor answer.question = question answer.title = request.data['title'] answer.description = request.data['description'] answer.language = request.data['language'] answer.save() return Response(AnswerSerializer(answer).data, status=status.HTTP_201_CREATED)
def create(self, validated_data): answer = Answer(**validated_data) answer.author = self.context['request'].user answer.save() return answer