diff options
| author | Tim Graham <timograham@gmail.com> | 2016-08-11 15:18:48 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-24 19:37:04 -0400 |
| commit | 325dd0befea3012c42eefa061f509fbdf1b6a8aa (patch) | |
| tree | 87d026fd736c1f8985cb1882e6a42e4bf7e76776 /docs | |
| parent | c4ee93128f1880c3993cf07619ff4e0524920a8e (diff) | |
[1.10.x] Fixed #27039 -- Fixed empty data fallback to model field default in model forms.
Backport of 4bc6b939944183533ae74791d21282e613f63a96 from master
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.10.1.txt | 3 | ||||
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/docs/releases/1.10.1.txt b/docs/releases/1.10.1.txt index 2fd860527a..719f536b29 100644 --- a/docs/releases/1.10.1.txt +++ b/docs/releases/1.10.1.txt @@ -79,3 +79,6 @@ Bugfixes * Reallowed subclassing ``UserCreationForm`` without ``USERNAME_FIELD`` in ``Meta.fields`` (:ticket:`27111`). + +* Fixed a regression in model forms where model fields with a ``default`` that + didn't appear in POST data no longer used the ``default`` (:ticket:`27039`). diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index df6bd6bd38..e2b57fe410 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -330,6 +330,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 |
