有没有办法将序列化程序上下文传递给类Meta?一般情况下,我想在Browsable API中包含嵌套API视图的URL,因此我将“渲染器”值传递给序列化器上下文,并希望在Meta中检查它以包含其他字段或不这样做 . 也许有更优雅的方式?
覆盖序列化程序 __init__ ,并根据 self.context['request'] 上的accepted renderer,随意切换 self.fields 中的超链接字段(动态更改字段为documentation example) .
__init__
self.context['request']
self.fields
1 回答
覆盖序列化程序
__init__
,并根据self.context['request']
上的accepted renderer,随意切换self.fields
中的超链接字段(动态更改字段为documentation example) .