diff options
| author | Tim Graham <timograham@gmail.com> | 2016-08-11 15:18:48 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-24 17:50:10 -0400 |
| commit | 4bc6b939944183533ae74791d21282e613f63a96 (patch) | |
| tree | 932a46a25fb5bfb8fa4b514762a4a2938f6f2b12 /docs/topics/forms | |
| parent | 426bca002c7902ceae230e0ce08a76dd6b6d3a06 (diff) | |
Fixed #27039 -- Fixed empty data fallback to model field default in model forms.
Diffstat (limited to 'docs/topics/forms')
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 9dcb2e3e53..4b5d7f27ce 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -332,6 +332,21 @@ Note that if the form :ref:`hasn't been validated ``form.errors``. A ``ValueError`` will be raised if the data in the form doesn't validate -- i.e., if ``form.errors`` evaluates to ``True``. +If an optional field doesn't appear in the form's data, the resulting model +instance uses the model field :attr:`~django.db.models.Field.default`, if +there is one, for that field. This behavior doesn't apply to fields that use +:class:`~django.forms.CheckboxInput` (or any custom widget with +``dont_use_model_field_default_for_empty_data=True``) since an unchecked +checkbox doesn't appear in the data of an HTML form submission. Use a custom +form field or widget if you're designing an API and want the default fallback +for a ``BooleanField``. + +.. versionchanged:: 1.10.1 + + Older versions don't have the exception for + :class:`~django.forms.CheckboxInput` which means that unchecked checkboxes + receive a value of ``True`` if that's the model field default. + This ``save()`` method accepts an optional ``commit`` keyword argument, which accepts either ``True`` or ``False``. If you call ``save()`` with ``commit=False``, then it will return an object that hasn't yet been saved to |
