Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.10.x] Fixed #27039 -- Fixed empty data fallback to model field def…
…ault in model forms. Backport of 4bc6b93 from master
- Loading branch information
Showing
6 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
timgraham
Author
Member
|
||
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): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit is causing problems with my formsets –
f.name
here should beform.add_prefix(f.name)
to account for prefixed forms. I'll come back to this and create a proper ticket and patch tomorrow.