Skip to content

Instantly share code, notes, and snippets.

@multimeric
Created September 30, 2019 07:18
Show Gist options
  • Save multimeric/932ae76b71c5cea79f45937b92a5ebe8 to your computer and use it in GitHub Desktop.
Save multimeric/932ae76b71c5cea79f45937b92a5ebe8 to your computer and use it in GitHub Desktop.
from marshmallow_jsonapi import fields, Schema
import json
class ProductSchema(Schema):
class Meta:
type_ = "products"
id = fields.String()
processes = fields.Relationship(
type_="processes",
id_field="id",
include_resource_linkage=True,
schema="ProcessSchema",
many=True
)
class ProcessSchema(Schema):
class Meta:
type_ = "processes"
id = fields.String()
meta = fields.ResourceMeta()
some_field = fields.String()
serialized = ProductSchema().dump({
"id": "1",
"processes": [
{
"id": 15,
"some_field": 123,
"meta": {
"order": "1"
}
}
]
})
print(json.dumps(serialized, indent=4))
assert 'meta' in serialized['data']['relationships']['processes']['data'][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment