django REST framework 在serialize的时候如何忽略空值?

klan 2013-12-16 06:06:38
现在的结果是:
{
"Arg": {
"Variety": "0.9",
"Distribution": "wandering",
"Adventurousness": "0.6",
"Genre": null
}
}


想要的结果是:
{
"Arg": {
"Variety": "0.9",
"Distribution": "wandering",
"Adventurousness": "0.6"
}
}

简单说就是,如果值为null,不需要显示.

我是用如下代码serialize的。我只要单纯的得到我现在需要的format就可以了.谢谢

class ArgSerializer(serializers.ModelSerializer):
class Meta:
app_label = 'music'
model = RadioStationArg
fields = ('Variety', 'Distribution', 'Adventurousness', 'Genre')
...全文
214 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧