Python SQLAlchemy列名和属性冲突

Python SQLAlchemy列名和属性冲突,python,sqlalchemy,Python,Sqlalchemy,我有一个表模式“project_table”,其中有一个列名为“status”。 问题是,我想用project.status属性覆盖并包装“status”列,该属性将包装status('str'),以方便此处未显示的其他情况 基本上我想这样做: project = Session().query( Project ).filter_by( id=ID ).one() print project.status #> will give <Status('act')> and no

我有一个表模式“project_table”,其中有一个列名为“status”。 问题是,我想用project.status属性覆盖并包装“status”列,该属性将包装status('str'),以方便此处未显示的其他情况

基本上我想这样做:

project = Session().query( Project ).filter_by( id=ID ).one()
print project.status #> will give <Status('act')> and not 'act'
检查,这可能会做你想要的,但老实说,像这样隐藏列名不是“干净”或良好的编码实践。这令人困惑


我的$0.02只是重命名列或重命名您尝试使用的属性

似乎可以使用Sql Alchemy的“”设置默认值,因为对象是从DB加载的

from sqlalchemy import orm

class Project(Base):
        __table__ = project_table

        def __init__(self, **columns):
            super(Project, self).__init__(**columns)

        @orm.reconstructor
        def init_on_load(self):
            # set status defaults here
from sqlalchemy import orm

class Project(Base):
        __table__ = project_table

        def __init__(self, **columns):
            super(Project, self).__init__(**columns)

        @orm.reconstructor
        def init_on_load(self):
            # set status defaults here