Skip to content

Commit 31bf597

Browse files
committed
Updated note on BooleanField required kwarg generation.
Closes encode#6474.
1 parent 1dc81ac commit 31bf597

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

docs/api-guide/fields.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ A boolean representation.
124124

125125
When using HTML encoded form input be aware that omitting a value will always be treated as setting a field to `False`, even if it has a `default=True` option specified. This is because HTML checkbox inputs represent the unchecked state by omitting the value, so REST framework treats omission as if it is an empty checkbox input.
126126

127-
Note that default `BooleanField` instances will be generated with a `required=False` option (since Django `models.BooleanField` is always `blank=True`). If you want to change this behaviour explicitly declare the `BooleanField` on the serializer class.
127+
Note that Django 2.1 removed the `blank` kwarg from `models.BooleanField`.
128+
Prior to Django 2.1 `models.BooleanField` fields were always `blank=True`. Thus
129+
since Django 2.1 default `serializers.BooleanField` instances will be generated
130+
without the `required` kwarg (i.e. equivalent to `required=True`) whereas with
131+
previous versions of Django, default `BooleanField` instances will be generated
132+
with a `required=False` option. If you want to control this behaviour manually,
133+
explicitly declare the `BooleanField` on the serializer class, or use the
134+
`extra_kwargs` option to set the `required` flag.
128135

129136
Corresponds to `django.db.models.fields.BooleanField`.
130137

0 commit comments

Comments
 (0)