marshmallow
marshmallow copied to clipboard
@field decorator to allow methods to return a Field object
This is different (in my opinion) from issue #738 or fields.Method.
This request is to define a decorator (maybe named @field) to decorate a method that returns a field without taking care of serialization or deserialization. This would be the same as the @declared_attr from SQLAlchemy.
The idea is to define a field which can make use of other class members.
>>> import marshmallow
>>> class MySchema(object):
... def __init__(self, schemes):
... self.schemes = schemes
...
... @marshmallow.field
... def url(self):
... return marshmallow.fields.Url(schemes=self.schemes)
...