Skip to content
Advertisement

Proper usage of “callable default function” in Django REST Framework (DRF)

Question:

How can I access the serializer instance or any relevant arguments in the default callable function of DRF field?


Scenario:

I have a serializer configuration as below,

JavaScript
and when I try to serialize the data as,
JavaScript

I am gettting error as,

JavaScript

Advertisement

Answer

Update
For DRF>=3.12, use this king of default class

JavaScript

pass a class instance instead of function to the default argument

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