Created
October 6, 2021 10:09
-
-
Save TSKGunGun/6016c8263daf5d217cdf477388b66985 to your computer and use it in GitHub Desktop.
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
def _post_clean(self): | |
opts = self._meta | |
exclude = self._get_validation_exclusions() | |
# Foreign Keys being used to represent inline relationships | |
# are excluded from basic field value validation. This is for two | |
# reasons: firstly, the value may not be supplied (#12507; the | |
# case of providing new values to the admin); secondly the | |
# object being referred to may not yet fully exist (#12749). | |
# However, these fields *must* be included in uniqueness checks, | |
# so this can't be part of _get_validation_exclusions(). | |
for name, field in self.fields.items(): | |
if isinstance(field, InlineForeignKeyField): | |
exclude.append(name) | |
try: | |
self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude) | |
except ValidationError as e: | |
self._update_errors(e) | |
try: | |
self.instance.full_clean(exclude=exclude, validate_unique=False) | |
except ValidationError as e: | |
self._update_errors(e) | |
# Validate uniqueness if needed. | |
if self._validate_unique: | |
self.validate_unique() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment