mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #27039 -- Fixed empty data fallback to model field default in model forms.
This commit is contained in:
parent
426bca002c
commit
4bc6b93994
6 changed files with 69 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue