These are the field in my PostSerializer
fields = ('id','user_id','title','desc','comments')
The user_id
and comments
are code generated and title
,desc
were obtained from api calls. I want to pass this as additional values to my request.data
. This is my APIView object
class PostView(APIView):
permission_classes = (IsAuthenticated,)
def post(self,request):
request.data['user_id'] = request.user.id
request.data['comments'] = "machine generated"
post_serializer = PostSerializer(data=request.data)
if post_serializer.is_valid():
post_serializer.save()
print(request.data)
return Response(post_serializer.data)
While my print(request.data)
shows user_id
,comments
fields and their corresponding values. In the saved database though the values for user_id
and comments
are null
.
How do we add and save additional parameters to a serializer object in django rest framework?