它看起来像 ndb.polymodel.PolyModel
类曾经有一个 class_name()
方法,但据我所知它已被弃用。
我有一个使用 Polymodel 的数据结构,其形式为具有两个子类的父 User 类 - Employee 和 Manager,并且我想在整个过程中进行一些基本检查以确定 User 对象是否属于 Employee 类或类(class)经理。
目前,我只是直接调用对象的 .__class__.__name__
属性,但我想知道为什么 PolyModel.class_name()
方法被弃用。有没有更好的方法来确定类继承?
最佳答案
根据上面的评论,您需要的是 isinstance(user, Employee)
/isinstance(user, Manager)
。
关于python - 确定 ndb PolyModel Google App Engine 中的对象类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40490923/