[Answered ]-Django rest framework how to return data field and success field

2๐Ÿ‘

โœ…

you will have to override the to_representation method on your list serializer class

define a list serializer class:

class StoreRotationListSerializer(serializers.ListSerializer):

    def to_representation(self, data):
        repr = super(StoreRotationListSerializer, self).to_representation(data)
        return {'data': repr}

now use this list serializer class in your main serializer:

class Store_RotationSerializer(ModelSerializer):

    class Meta:
        model = Store_Rotation
        fields = '__all__'
        list_serializer_class = StoreRotationListSerializer

read more about list serializer here: http://www.django-rest-framework.org/api-guide/serializers/#listserializer

๐Ÿ‘คzaphod100.10

0๐Ÿ‘

You can write a custom renderer and assign that if you want to use it often. Here is an example. Otherwise you can return a Response manually by overriding the corresponding viewset function.

๐Ÿ‘คhurturk

Leave a comment