sqlalchemy:一个用于多个视图的基类

时间:2018-12-02 15:41:02

标签: python orm sqlalchemy sql-view

在sqlite数据库中,我有一个名为 variant 的表和多个具有相同结构的视图。 ( variant1 variant2 variant3 ...)
我想拥有一个可以映射到视图并在运行时切换的python类。

class Variant(Base):
     __tablename__="variant"
     id = Column(Integer,primary_key=True)
     name = Column(String)


# show all variant 
for i in session.query(Variant):
   print(i.name)

# show only variant from view called variant1 
# But this is not working. any idea ? 

Variant.__tablename__ = "variant1"
for i in session.query(Variant):
    print(i.name)

0 个答案:

没有答案