relationships.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:aiohttp_json_api 作者: vovanbo 项目源码 文件源码
def serialize(self, schema, data, **kwargs) -> typing.MutableMapping:
        """Composes the final relationships object."""
        document = OrderedDict()

        if data is None:
            document['data'] = data
        elif isinstance(data, Mapping):
            # JSON API resource linkage or JSON API relationships object
            if 'type' in data and 'id' in data:
                document['data'] = data
        else:
            # the related resource instance
            document['data'] = \
                schema.ctx.registry.ensure_identifier(data, asdict=True)

        links = kwargs.get('links')
        if links is not None:
            document['links'] = links

        return document
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号