marshmallow icon indicating copy to clipboard operation
marshmallow copied to clipboard

@field decorator to allow methods to return a Field object

Open jimmy-lt opened this issue 6 years ago • 0 comments

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)
...

jimmy-lt avatar Sep 29 '19 11:09 jimmy-lt