Given a sqlalchemy model class
class Table(Base):
__table__name = 'table'
col1 = Column(...)
rel = relationship(...)
If you look at Table, both col1 and rel are of type InstrumentedAttribute
. How can I distinguish these two? I tried to look into their attributes. But there are too many...and there's no document about this matter.
Check the type of Table.<column>.property
which can commonly be either instance of ColumnProperty or RelationshipProperty:
>>> type(Table.col1.property)
<class 'sqlalchemy.orm.properties.ColumnProperty'>
>>> type(Table.rel.property)
<class 'sqlalchemy.orm.relationships.RelationshipProperty'>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With