Skip to content

No good way to access nested serializers #5520

@jonathan-golorry

Description

@jonathan-golorry

It would be nice to be able to access child serializers from their parent and have them work as fully functional serializer instances. Using serializer_instance.fields['<child_name>'] gets the right serializer, but it doesn't have data or a model instance associated with it. From the child serializer, you have to do something like self.parent.instance.<child_relation> to access the model instance.

I understand that there is no intention to support nested writes/updates, but is changing the nesting structure of serializers something that might be done? I think a dynamic-programming-inspired approach would be more intuitive.

BaseSerializer is already a subclass of Field, so it should be possible. I haven't looked into how much of a rewrite it would require, as I wanted to get people's reactions first. Is there a solid reason things aren't done this way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions