2012-04-07 3 views
1

私はいくつかのORMベースのクラスの特定の列をシリアル化する必要があります。私は、ORMクラスの作成で指定された列にデフォルト値を設定します。SQLAlchemy ORMクラスから列値のdictを生成する方法は?

class AXSection(Base): 
    __tablename__ = 'axsection' 
    __table_args__ = {'mysql_engine':'ISAM', 'mysql_charset':'utf8'} 
    id = Column(BigInteger, primary_key=True) 
    enabled = Column(String(1), nullable=False, default='T') 
    pages = relationship('AXPage', backref='axsection')a 
    name = Column(String(255), nullable=False) 

どのようにして列の名前を返す方法を記述しますか?

答えて

3

属性には列名のリストが含まれています。あなたの例のAXSectionタイプに関連付けられている列名を印刷するには、使用:中

print AXSection.__table__.columns 

結果:

['axsection.id', 'axsection.enabled', 'axsection.name'] 
+0

答えにタイプミスがあります。 AXSection .__ table __。columsはAXSection .__ table __である必要があります。 stackoverflowには少なくとも6文字の編集が必要なので修正できませんでした。 – gorantq

+0

キャッチをありがとう。回答が編集されました – user590028

関連する問題