Python marshmallow.fields 模块,Method() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用marshmallow.fields.Method()

项目:microcosm-flask    作者:globality-corp    | 项目源码 | 文件源码
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",
    })))
项目:toasted-marshmallow    作者:lyft    | 项目源码 | 文件源码
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()