1👍
✅
You can not send the request
directly as context=…
to the serializer. The context should be a dictionary-like object.
What you can do is construct a dictionary where you map the request
to the request, like:
serializer = self.serializer_class(post, context={'request': request })
Then you can use this as:
class PostSerializer(serializers.ModelSerializer):
# ⋮
def create(self, validated_data):
"""Create a blog post in a customized way."""
tags = validated_data.pop('tags', [])
post = Post.objects.create(**validated_data, owner=self.context['request'].user)
# ⋮
Source:stackexchange.com