小编Ahm*_*med的帖子

检查对象是否是sqlalchemy模型实例

我想知道如果知道一个对象,它是否是sqlalchemy映射模型的一个实例.

通常,我会使用isinstance(obj,DeclarativeBase).但是,在这种情况下,我没有使用可用的DeclarativeBase类(因为它在依赖项目中).

我想知道在这种情况下最佳做法是什么.

class Person(DeclarativeBase):
      __tablename__ = "Persons"

p = Person()

print isinstance(p, DeclarativeBase)
#prints True

#However in my scenario, I do not have the DeclarativeBase available
#since the DeclarativeBase will be constructed in the depending web app
#while my code will act as a library that will be imported into the web app
#what are my alternatives?
Run Code Online (Sandbox Code Playgroud)

sqlalchemy

7
推荐指数
1
解决办法
2388
查看次数

标签 统计

sqlalchemy ×1