如何解决烧瓶棉花糖从嵌套字典中删除键
我有以下架构:
class PublisherSchema(ma.SQLAlchemyAutoSchema):
class Meta:
fields = ('name',)
model = Publisher
class JournalSchema(ma.SQLAlchemyAutoSchema):
class Meta:
fields = ('title','publisher')
model = Journal
ordered = True
publisher = ma.Nested(PublisherSchema)
当我转储 JournalSchema 时,我希望结果是:
{
"title": "hello","publisher: "bye"
}
但现在它转储为:
{
"title": "hello","publisher": {
"name": "bye"
}
}
如何嵌套发布者值但不显示键?
解决方法
其实我想通了。方法是:
class JournalSchema(ma.SQLAlchemyAutoSchema):
publisher = fields.String(attribute="publisher.name")
class Meta:
fields = ('title','publisher')
model = Journal
ordered = True
这认为“发布者”是引用模型的关系。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。