Python 2.7 更新SQLAlchemy中的派生值

Python 2.7 更新SQLAlchemy中的派生值,python-2.7,sqlalchemy,Python 2.7,Sqlalchemy,通常的sqlalchemy用法: my_prop=列(“my_prop”,文本) 我想要不同的语义。假设一个对象有一组字段(propA、propB、propC)。我想维护一个从这些字段派生的数据库列(比如说,propA+propB+propC)。我希望只要这些字段中的任何一个被更新,该列就会被更新。谢谢。提供您需要的功能。它们允许您编写在查询中可用的python属性 如果您希望有一个name列并提供对first-name和last-name属性的访问,可以从这里开始 @hybrid_proper

通常的sqlalchemy用法:

my_prop=列(“my_prop”,文本)

我想要不同的语义。假设一个对象有一组字段(propA、propB、propC)。我想维护一个从这些字段派生的数据库列(比如说,propA+propB+propC)。我希望只要这些字段中的任何一个被更新,该列就会被更新。谢谢。

提供您需要的功能。它们允许您编写在查询中可用的python属性

如果您希望有一个name列并提供对first-name和last-name属性的访问,可以从这里开始

@hybrid_property
def first_name(self):
    # get the first name from the name column

@first_name.setter
def first_name(self, value):
    # update the name column with the first name replaced

@first_name.expression
def first_name(cls):
    # return a sql expression that extracts the first name from the name column
    # this is appropriate to be used in queries