4👍
✅
So, from what I can see in your code, you are creating the serializer manually without adding the context. In most cases, allowing the CreateView
create the serializer by itself suffices but if you really need to create it by yourself, then you need to remember to pass the context. Somthing like this:
context = {'request': self.request}
write_serializer = MultipleOrderSerializer(data=request.data, context=context)
You can check the view’s get_serializer()
method to see how a serializer is properly created. I really advice that you refactor your code and try to use the existing solution for creating serializers
Source:stackexchange.com