def unwrap_request(self, data, many):
if 'data' not in data:
raise ma.ValidationError('Object must include `data` key.')
data = data['data']
data_is_collection = ma.utils.is_collection(data)
if many:
if not data_is_collection:
raise ma.ValidationError([{'detail': '`data` object must be a collection.',
'source': {'pointer': '/data'}}])
return [self.unwrap_item(each) for each in data]
if data_is_collection:
raise ma.ValidationError([
{'detail': '`data` object must be an object, not a collection.',
'source': {'pointer': '/data'}}])
if data is None:
# When updating relationships we need to specially handle the primary data being null.
# http://jsonapi.org/format/1.1/#crud-updating-to-one-relationships
raise NullPrimaryData()
return self.unwrap_item(data)
评论列表
文章目录