Django Rest Framework serialization error in ListAPIView

I get below the error

Error - 'many' is an invalid keyword argument for this function

In ListAPIView when serializing an object.

class UserSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = ('id', 'uuid', 'email', 'password', 'first_name', 'last_name', 'mobile_no', 'dob', 'username',)


class CorporateProfileSerializer(serializers.ModelSerializer):
     user = UserSerializer(many=True)

     class Meta:
        model = CorporateProfile
        fields = ('user', 'id', 'uuid', 'company_name', 'company_type',)

views.py

class CorporateListView(ListAPIView):
    serializer_class = CorporateProfile
    queryset = CorporateProfile.objects.all()

What am I doing wrong here?

+4
source share
1 answer

It was my mistake in thinking. I wrote a model in the serializer class instead of the serializer class.

serializer_class = CorporateProfileSerializer
+4
source

Source: https://habr.com/ru/post/1626538/


All Articles