Now, we will create a simple Marshmallow schema that we will use to validate, serialize, and deserialize the previously declared SurfboardMetricModel model.
Stay in the metrics.py file in the metrics/metrics/models subfolder. Add the following lines to declare SurferStatus Enum and the SurfboardMetricSchema class. The code file for the sample is included in the restful_python_2_09_01 folder, in the Pyramid01/metrics/metrics/models/metrics.py file:
class SurferStatus(Enum): IDLE = 0 PADDLING = 1 RIDING = 2 RIDE_FINISHED = 3 WIPED_OUT = 4 class SurfboardMetricSchema(Schema): id = fields.Integer(dump_only=True) status = EnumField(SurferStatus, required=True) speed_in_mph = fields.Integer(required=True) altitude_in_feet = fields.Integer(required=True) ...