1
獲取關係元數據我有一個非常簡單的用戶類定義:從SQLAlchemy的
class User(Base):
implements(interfaces.IUser)
__tablename__ = 'users'
#Fields description
id = Column(Integer, primary_key=True)
client_id = Column(Integer, ForeignKey('w2_client.id'))
client = relationship("Client", backref=backref('users', order_by=id))
我想自動生成GUI編輯的對象的用戶(和其他類型的類)。所以,我需要獲得表的所有元數據,例如,我可以這樣做:
for c in User.__table__.columns:
print c.name, c.type, c.nullable, c.primary_key, c.foreign_keys
但我不能得到有關的關係「客戶端」的任何信息,該c.foreign_keys只顯示我的表與foreign_keys有關,但不是我定義的屬性「client」。 請讓我知道如果我的問題不明確
您剛剛確認沒有乾淨的方式來做到這一點。我現在的解決方案是使用一個字典來定義我需要的所有信息。感謝您的支持! – nam