mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
[1.10.x] Fixed #27039 -- Fixed empty data fallback to model field default in model forms.
Backport of 4bc6b93994 from master
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user