dynamorm
dynamorm copied to clipboard
Provide dumps() method
The current docs do not give an example of serialization support for JSON.
I attempted to use Marshmallow's dumps feature
db.MyModel.Schema.dumps(someInstanceOfMyModel)
# throws this error:
TypeError: dumps() missing 1 required positional argument: 'obj' marshmallow
But received an error. I am currently using someInstanceOfMyModel._raw
to get the data for JSON output.
Feature Request Add a expose a dumps method to get a dict.
db.MyModel.dumps(someInstanceOfMyModel)
Add a expose a dumps method to get a dict.
If you only want a dict
, you can use the to_dict()
method.
Try this: someInstanceOfMyModel.to_dict()
.
The obj
value that's missing is the instance. You need to use an instantiated Schema
:
db.MyModel.Schema().dumps(someInstanceOfMyModel)
I think that the interface of the dumped data from that will vary depending on whether you have marshmallow 2.x or 3.x installed. There was a breaking api change between the two. My project uses marshmallow 2.x so I'm used to doing this to get the dumped data:
data, errors = db.MyModel.Schema().dumps(someInstanceOfMyModel)
# data will the serialized object, errors will be any errors encountered during serialization