1
votes

I created a checkbox and I want to set its default value to false so that it is unchecked by default.I tried in four ways but still the checkbox is checked by default.

raw = fields.Boolean(default=0)
raw = fields.Boolean(default='0')
raw = fields.Boolean(default=False)
raw = fields.Boolean(default='False')
3

3 Answers

2
votes

Default it's None for boolean field not False(you can check into the database without setting up default value of any boolean field, you will see there None not False), so you just need to set like that

raw = fields.Boolean(string='Raw', default=False)
2
votes

By default value of Boolean field is false so you don't need to set it default value.

Now regarding your query :

raw = fields.Boolean(default='0')
raw = fields.Boolean(default='False')

Both these syntax are using string '0' and 'False' which is True by logic

you can use

raw = fields.Boolean(default=0)
raw = fields.Boolean(default=False)
0
votes

This is an option too:

def default_value(self)
    <code here>
    return something
var = fields.Integer(default=default_value)