我正在尝试为 Db 模型编写一个装饰器,以使该模型可序列化
def Schema(cls):
class Schema(marshmallow.ModelSchema):
class Meta:
model = cls
cls.Schema = Schema
return cls
@Schema
class SerialInterface(sql.Model, InheritanceModel):
id = sql.Column(types.Integer, primary_key=True)
transmission_rate = sql.Column(types.Integer)
type = sql.Column(sql.String(50))
mad_id = sql.Column(types.Integer, sql.ForeignKey('mad.id'))
serial_protocol = sql.relationship(SerialProtocol, uselist=False, cascade="all, delete-orphan")
但我想在这个装饰器中传递嵌套对象,像这样:
@Schema(nested=['serial_protocol'])
class SerialInterface(sql.Model, InheritanceModel):