[Fixed]-Djangorestframework – Boolean field with default value True changes to False

5👍

If you don’t want to update is_searchable you have to define it as read_only field in your serializer class.

Eg:

class YourSerializer(serializers.ModelSerializer):
    is_searchable = serializers.BooleanField(read_only=True)

otherwise, pass the correct value true/false

👤grigno

0👍

I had a similar issue and I found it has to do with my curl command. You must add -H "Content-Type: application/json" .
e.g.

curl -X PUT -H "Content-Type: application/json" -d '{"is_searchable": true}' http://<your-instance>/<your-api>/
👤192dot

-2👍

You may use initial

class YourSerializer(serializers.ModelSerializer):
    is_searchable = serializers.BooleanField(initial=True)

Leave a comment