Переименовать поле во вложенном сериализаторе - Django Rest Framework - PullRequest
0 голосов
/ 15 апреля 2020

Я пытаюсь переименовать поле в моем сериализаторе, например:

class ExampleTwoSerializer(serializers.ModelSerializer):

    class Meta:
        model = ExampleTwo
        exclude = ("some_field", "another_field")


class ExampleOneSerializer(CustomModelSerializer):
    new_fied = ExampleOneSerializer(source="example_model_field", many=True)

    class Meta:
        model = ExampleOne
        exclude = ("some_field", "another_field")

Но я получаю эту ошибку:

AttributeError at /api/example/
Got AttributeError when attempting to get a value for field `new_field` on serializer `ExampleTwoSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `ExampleTwo` instance.
Original exception text was: 'ExampleTwo' object has no attribute 'new_fied'.
...