コード例 #1
0
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)
コード例 #2
0
 def create(self, validated_data):
     answer = Answer(**validated_data)
     answer.author = self.context['request'].user
     answer.save()
     return answer