mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
parent
1dc81acb4d
commit
31bf597081
|
@ -124,7 +124,14 @@ A boolean representation.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
Note that Django 2.1 removed the `blank` kwarg from `models.BooleanField`.
|
||||||
|
Prior to Django 2.1 `models.BooleanField` fields were always `blank=True`. Thus
|
||||||
|
since Django 2.1 default `serializers.BooleanField` instances will be generated
|
||||||
|
without the `required` kwarg (i.e. equivalent to `required=True`) whereas with
|
||||||
|
previous versions of Django, default `BooleanField` instances will be generated
|
||||||
|
with a `required=False` option. If you want to control this behaviour manually,
|
||||||
|
explicitly declare the `BooleanField` on the serializer class, or use the
|
||||||
|
`extra_kwargs` option to set the `required` flag.
|
||||||
|
|
||||||
Corresponds to `django.db.models.fields.BooleanField`.
|
Corresponds to `django.db.models.fields.BooleanField`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user