[Answered ]-Django declaring a read-only field on serializer

1👍

You should specify read_only=True to mark the field as readonly. By customizing it yourself, you prevented Django from doing this itself:

class OrderSerializer(serializers.ModelSerializer):
    orderId = serializers.UUIDField(source='id', read_only=True)
    orderName = serializers.CharField(source='name')

    class Meta:
        model = Order
        fields = (
            'orderId',
            'orderName',
        )
        read_only_fields = ('orderId',)

Leave a comment