Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant