Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. class CompositeNested(fields.Nested):
  2.  
  3.     def _deserialize(self, value, attr, data):
  4.         data = super(CompositeNested, self)._deserialize(value, attr, data)
  5.         return tuple(data[k] for k in self.schema.fields.keys())
  6.  
  7. class ValueWithUnitSchema(Schema):
  8.     value = fields.Float()
  9.     unit = fields.String()
  10.  
  11.     class Meta:
  12.         strict = True
  13.         ordered = True
  14.  
  15. class MonthRangeValueWithUnitSchema(Schema):
  16.     from_month = fields.Integer()
  17.     to_month = fields.Integer()
  18.     value = CompositeNested(ValueWithUnitSchema)
  19.  
  20.     class Meta:
  21.         strict = True
  22.         ordered = True
  23.  
  24. class MySchema(ModelSchema):
  25.     field_of_model = fields.List(CompositeNested(MonthRangeValueWithUnitSchema), required = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement