Issue
all the django rest framework docs assume your going to instantly save the data. But what if I want access to the serializer data? What if I want to do something with it. Or if the serializer contains info other than what I need to save in a model?
is the validated_data
attribute what we need?
So
validatedData = serializer.validated_data
userid = validatedData.get('id')
would work right?
Solution
Yes you are right, but remember the validated_data
is generate only after you call .is_valid()
method. For example:
serializer.is_valid()
# do it first ^^^^^
validatedData = serializer.validated_data
userid = validatedData.get('id')
You can look on example saving-instances in the docs
Answered By - Brown Bear
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.