django-json-api/django-rest-framework-json-api

Getting resource_name dynamically

Adman opened this issue · 0 comments

Adman commented

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?