Reputation: 638
is there a way to pass serializer context to class Meta? In general, I want to include a URL to nested API views only in Browsable API, so I pass a 'renderer' value to serializer context, and want to check it in Meta to include additional fields or not to do so. Maybe there is a more elegant way?
Upvotes: 1
Views: 229
Reputation: 2099
Override your serializer __init__
and switch out the hyperlinked field in self.fields
for whatever you please (documentation example for dynamically changing fields) based on the accepted renderer on self.context['request']
.
Upvotes: 1