我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用marshmallow.fields.Method()。
def test_field_decorated_method(): parameter = build_parameter(TestSchema().fields["decorated"]) assert_that(parameter, is_(equal_to({ # NB: default for `fields.Method` is "object" "type": "string", })))
def schema(): class BasicSchema(Schema): class Meta: ordered = True foo = fields.Integer(attribute='@#') bar = fields.String() raz = fields.Method('raz_') meh = fields.String(load_only=True) blargh = fields.Boolean() def raz_(self, obj): return 'Hello!' return BasicSchema()