我想知道如何知道給定對象是否是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?
提供更多信息! – shahjapan