From 31bf59708121127994bdbcd038f4f76bb28059d7 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 1 Mar 2019 12:48:12 +0100 Subject: [PATCH] Updated note on BooleanField required kwarg generation. Closes #6474. --- docs/api-guide/fields.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 8d25d6c78..74ce2251d 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -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. -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`.