Skip to content

Getting resource_name dynamically #931

Closed

Description

@Adman

I have the following structure of serializers

class A(Serializer)
    class JSONAPIMeta:
        resource_name = "A"

class B(Serializer)
    class JSONAPIMeta:
        resource_name = "B"

class MySerializer(Serializer)
    my_field = OneOfSerializer(A(), B())

OneOfSerializer is my custom serializer accepting values either for A or B. The main problem is that it doesn't contain JSONAPIMeta and DRF-jsonapi raises an exception. Would it be possible to somehow return the resource_name dynamically based on the data, so that the relation is correctly set?

Activity

  1. locked and limited conversation to collaborators on Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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