Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

djangorestframework - Boolean field with default value True changes to False

I have, among various other fields, a boolean field like below in my models.py:

is_searchable = models.BooleanField(default=True)

When using PUT request to modify either of the fields of the model, value of is_searchable changes to False even if nothing related to it is specified in the PUT request.

I am using serializers.ModelSerializer here. Version of django rest framework - 3.0.1

like image 799
Dharmit Avatar asked May 05 '15 08:05

Dharmit


1 Answers

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

like image 127
grigno Avatar answered Nov 10 '22 01:11

grigno