我将模型声明为:
class SAProduct(Base):
sku = Column(PRODUCT_SKU_TYPE, primary_key=True)
i_want_to_hide = Column(String(20), nullable=False)
name = Column(Unicode(255), nullable=True)
@property
def my_property(self):
return i_calculate_property_here(self)
和 Spyne 模型声明为:
db = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=db)
class TableModel(ComplexModelBase):
__metaclass__ = ComplexModelMeta
__metadata__ = MetaData(bind=db)
class SProduct(TableModel):
__table__ = SAProduct.__table__
如何使属性i_want_to_hide
从 Spyne 模型中排除,并将属性my_property
包含为 Spyne 模型属性?
PS 现在我使用猴子补丁 Spyne 来支持这种语法:
class SProduct(GComplexModel):
__model__ = Product
class Attributes:
exclude_attrs = ('i_want_to_hide',)
add_attrs = {'my_property': Boolean}
但我想摆脱它。