polymodel.py 文件源码

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

项目:xxNet 作者: drzorm 项目源码 文件源码
def from_entity(cls, entity):
    """Load from entity to class based on discriminator.

    Rather than instantiating a new Model instance based on the kind
    mapping, this creates an instance of the correct model class based
    on the entities class-key.

    Args:
      entity: Entity loaded directly from datastore.

    Raises:
      KindError when there is no class mapping based on discriminator.
    """
    if (_CLASS_KEY_PROPERTY in entity and
        tuple(entity[_CLASS_KEY_PROPERTY]) != cls.class_key()):
      key = tuple(entity[_CLASS_KEY_PROPERTY])
      try:
        poly_class = _class_map[key]
      except KeyError:
        raise db.KindError('No implementation for class \'%s\'' % (key,))
      return poly_class.from_entity(entity)
    return super(PolyModel, cls).from_entity(entity)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号