Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including list of nested when serializing #308

Open
g-brizolier opened this issue May 21, 2020 · 0 comments
Open

including list of nested when serializing #308

g-brizolier opened this issue May 21, 2020 · 0 comments

Comments

@g-brizolier
Copy link

I am using json:api with python with a class that looks like this:

class ChildrenResultSerializer(JSONAPISerializer):
  children = fields.List(fields.Nested(ChildSerializer), allow_none=True)

and the other one looks like this:

class ChildSerializer(JSONAPISerializer):
    toys = fields.Relationship(
        many=True,
        type_="toys",
        include_resource_linkage=True,
        schema=ToySerializer,
        allow_none=True,
    )

In the ChildrenResultSerializer.serialize function, I want to be able to see the toys data for each of the children. I'm using it like this:

ChildrenResultSerializer.serialize(results, include_data=("children.toys"))

but I get this error: ValueError: Can only include relationships. "children" is a "List"

what am I doing wrong? I would like to keep children as a list of nested if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant