Ejemplo n.º 1
0
def add_question(request, user_id):

    mentee = Mentee.objects.get(id=user_id)
    question = Question()
    question.author = mentee
    question.title = request.data['title']
    question.description = request.data['description']
    question.language = request.data['language']
    question.save()
    return Response(QuestionSerializer(question).data,
                    status=status.HTTP_201_CREATED)
Ejemplo n.º 2
0
    def create(self, validated_data):
        question_tags = validated_data.pop('tags', None)
        question = Question(**validated_data)
        question.author = self.context['request'].user
        question.save()

        for request_tag in question_tags:
            tag_name = request_tag.get('name')
            if not Tag.objects.filter(name=tag_name).exists():
                tag = create_tag(request_tag)
            else:
                tag = Tag.objects.filter(name=tag_name)[0]
            qt = QuestionTag.objects.create(
                question=question,
                tag=tag,
            )
            qt.save()

        question.save()
        return question