Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CompositeNested(fields.Nested):
- def _deserialize(self, value, attr, data):
- data = super(CompositeNested, self)._deserialize(value, attr, data)
- return tuple(data[k] for k in self.schema.fields.keys())
- class ValueWithUnitSchema(Schema):
- value = fields.Float()
- unit = fields.String()
- class Meta:
- strict = True
- ordered = True
- class MonthRangeValueWithUnitSchema(Schema):
- from_month = fields.Integer()
- to_month = fields.Integer()
- value = CompositeNested(ValueWithUnitSchema)
- class Meta:
- strict = True
- ordered = True
- class MySchema(ModelSchema):
- field_of_model = fields.List(CompositeNested(MonthRangeValueWithUnitSchema), required = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement