python - Nesting generic fields in Marshmallow -


i trying marshmallow orm library here. have general reporting schema form:

    class reportingqueryresultschema(ma.schema):          start_date = fields.str(required=true)          end_date = fields.str(required=true)          data = fields.nested(              reportingdataschema,              required=true,              many=true         ) 

reportingdataschema generic field. can different types of schema. first instinct here inheritance. try this:

    class reportingdataschema(ma.schema):         pass      class fooschema(reportingdataschema):         value = fields.str()      class barschema(reportingdataschema):         thing = fields.str() 

marshmallow fails serialize nested fields, giving me following:

    {          "data": [               {}          ],         "end_date": "2017-06-05",         "start_date": "2017-06-01"     } 

but if declare reportingqueryresultschema as:

    class reportingqueryresultschema(ma.schema):         start_date = fields.str(required=true)         end_date = fields.str(required=true)         data = fields.nested(              fooschema,   # replaced here              required=true,              many=true         ) 

it able detect nested schema , populate result.

    {          "data": [               {"key": "val"}          ],         "end_date": "2017-06-05",         "start_date": "2017-06-01"     } 

what correct way generic nested schema in marsmallow?


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -