Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pass #user #serializer #django #rest #framework
ADD COMMENT
Topic
Name
5+6 =