码迷,mamicode.com
首页 > 数据库 > 详细

dynamically creating a set of SQLAlchemy table

时间:2015-08-14 19:46:44      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

if you want to create multiple table objects, you could create a function to generate and return a new class. Maybe something like this:


Base = declarative_base()

def TableCreator(tablename):
    class MyTable(Base):
        __tablename__ = tablename
        row_id = Column(INT, primary_key=True)
        another_column = Column(CHAR(10))
    return MyTable



Then you could call it with mytable1 = TableCreator("mytable1").

dynamically creating a set of SQLAlchemy table

标签:

原文地址:http://my.oschina.net/u/2007546/blog/492513

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!