def get_fields(self):
        """Dynamically adapt fields based on the current request."""
        fields = super(CollectionSerializer, self).get_fields()

        if self.request.method == "GET":
            fields['data'] = serializers.SerializerMethodField()
        else:
            fields['data'] = serializers.PrimaryKeyRelatedField(many=True, read_only=True)

        return fields
Dynamically adapt fields based on the current request.