Created
September 30, 2019 07:18
-
-
Save multimeric/932ae76b71c5cea79f45937b92a5ebe8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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