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 /django/forms/models.py | |
| parent | 426bca002c7902ceae230e0ce08a76dd6b6d3a06 (diff) | |
Fixed #27039 -- Fixed empty data fallback to model field default in model forms.
Diffstat (limited to 'django/forms/models.py')
| -rw-r--r-- | django/forms/models.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/forms/models.py b/django/forms/models.py index 7cb2159b1d..628d96b237 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -52,6 +52,11 @@ def construct_instance(form, instance, fields=None, exclude=None): continue if exclude and f.name in exclude: continue + # Leave defaults for fields that aren't in POST data, except for + # checkbox inputs because they don't appear in POST data if not checked. + if (f.has_default() and f.name not in form.data and + not getattr(form[f.name].field.widget, 'dont_use_model_field_default_for_empty_data', False)): + continue # Defer saving file-type fields until after the other fields, so a # callable upload_to can use the values from other fields. if isinstance(f, models.FileField): |
