pass user to serializer django rest framework

66

pass user to serializer django rest framework -

class CommentSerializer(serializers.Serializer):
    ...

    def create(self, validated_data):
      user = self.context['request'].user
      comment = Comment.objects.create(
         user=user, 
         **validated_data
      )
      return comment

Comments

Submit
0 Comments