Skip to content
Advertisement

DRF: How to pass extra context data to serializers

I was searching the net and found the similar problem but it doesn’t work in my case, Idk why. I try to put some extra data to context in serializer, but get only 3 default fields: request, view and format and no mention for my custom data.

My model:

JavaScript

My Serializer:

JavaScript

My ModelViewSet:

JavaScript

I was debugging it through PyCharm and Postman but still can’t understand where is my mistake. Hope you will help me to fix it.

Advertisement

Answer

Your code is right.It should work. But i don’t know where is the issue.You can try the modified code as below.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement