Reputation: 215
I have a task for nested insertion. I have figured out that by overriding the create method in serializer. But I need to have user email for insertion. How do I get the email in serializer efficiently?
Upvotes: 0
Views: 413
Reputation: 5194
Serializers are passed a context dictionary, which contains the view instance, so you could get the user
by doing something like this:
request = self.context.get('request', None)
if request is not None:
email = request.user.email
Upvotes: 3