我要反序列化json模型
class LogsSchema(ModelSchema):
class Meta:
model = Logs
sqla_session = Session
class UsersSchema(ModelSchema):
logs = fields.Nested(LogsSchema,exclude=('User', ))
class Meta:
model = Users
sqla_session = Session
json模型请求
<QueryDict: {u'Username': [u'ramin world'], u'logs': [u'[UserLog=test]'], u'Date': [u'null'], u'Password': [u'1234'], u'Email': [u'ramin@blacat.gmail.com'], u'Name': [u'Farajpour']}>
加载json请求:
users_schema = UsersSchema()
json_dict = users_schema.load(usermodel,session=Session).data
结果:
{'Username': u'ramin world', 'Password': u'1234', 'Name': u'Farajpour', 'Email': u'ramin@blacat.gmail.com'}
您认为模型u'logs': [u'[UserLog=test]']
不在结果上。
答案 0 :(得分:0)
尝试在日志中添加many=True
:
class UsersSchema(ModelSchema):
logs = fields.Nested(LogsSchema,exclude=('User', ), many=True)
...