[Django]-Why does my "id" field disappear in my serializer (manytomany)?


As docs says in https://www.django-rest-framework.org/api-guide/serializers/#customizing-multiple-update:

You will need to add an explicit id field to the instance serializer. The default implicitly-generated id field is marked as read_only. This causes it to be removed on updates. Once you declare it explicitly, it will be available in the list serializer’s update method.

So you should declare id yourself for being able to use that:

class PriceLineSerializerTest(serializers.ModelSerializer):
    id = serializers.IntegerField()

    class Meta:
        model = PriceLine
        exclude = ['id', ...]

Leave a comment