Fixed #24771 -- Simplified ModelForm._post_clean()
This code added in45e049937d
is no longer necessary to pass the model_formsets_regress tests as of5e2c4a4bd1
.
This commit is contained in:
parent
4f8cbf08be
commit
681df1aeaf
|
@ -411,10 +411,6 @@ class BaseModelForm(BaseForm):
|
||||||
opts = self._meta
|
opts = self._meta
|
||||||
|
|
||||||
exclude = self._get_validation_exclusions()
|
exclude = self._get_validation_exclusions()
|
||||||
# a subset of `exclude` which won't have the InlineForeignKeyField
|
|
||||||
# if we're adding a new object since that value doesn't exist
|
|
||||||
# until after the new instance is saved to the database.
|
|
||||||
construct_instance_exclude = list(exclude)
|
|
||||||
|
|
||||||
# Foreign Keys being used to represent inline relationships
|
# Foreign Keys being used to represent inline relationships
|
||||||
# are excluded from basic field value validation. This is for two
|
# are excluded from basic field value validation. This is for two
|
||||||
|
@ -425,12 +421,10 @@ class BaseModelForm(BaseForm):
|
||||||
# so this can't be part of _get_validation_exclusions().
|
# so this can't be part of _get_validation_exclusions().
|
||||||
for name, field in self.fields.items():
|
for name, field in self.fields.items():
|
||||||
if isinstance(field, InlineForeignKeyField):
|
if isinstance(field, InlineForeignKeyField):
|
||||||
if self.cleaned_data.get(name) is not None and self.cleaned_data[name]._state.adding:
|
|
||||||
construct_instance_exclude.append(name)
|
|
||||||
exclude.append(name)
|
exclude.append(name)
|
||||||
|
|
||||||
# Update the model instance with self.cleaned_data.
|
# Update the model instance with self.cleaned_data.
|
||||||
self.instance = construct_instance(self, self.instance, opts.fields, construct_instance_exclude)
|
self.instance = construct_instance(self, self.instance, opts.fields, exclude)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.instance.full_clean(exclude=exclude, validate_unique=False)
|
self.instance.full_clean(exclude=exclude, validate_unique=False)
|
||||||
|
|
Loading…
Reference in New Issue