在 ndb PolyModel Google App Engine 中确定 object class

Determining object class in ndb PolyModel Google App Engine

看起来 ndb.polymodel.PolyModel class 曾经有一个 class_name() 方法,但据我所知它已被弃用。

我有一个使用多模型的数据结构,其形式为 parent 用户 class 和两个 child classes - 员工和经理,我想要在整个过程中进行一些基本检查以确定用户 object 是 class 员工还是 class 经理。

目前,我只是直接调用 object 的 .__class__.__name__ 属性,但我想知道为什么不推荐使用 PolyModel.class_name() 方法。是否有更好的方法来确定 class 继承?

根据上面的评论,您似乎需要的是 isinstance(user, Employee) / isinstance(user, Manager)