def _post_clean(self):
        opts = self._meta

        # Update the model instance with self.cleaned_data.
        self.instance = construct_instance(self, self.instance, opts.fields,
                                           opts.exclude)
        changed_fields = getattr(self.instance, '_changed_fields', [])

        exclude = self._get_validation_exclusions()
        try:
            for f in self.instance._fields.values():
                value = getattr(self.instance, f.name)
                if f.name not in exclude:
                    f.validate(value)
                elif value in EMPTY_VALUES and f.name not in changed_fields:
                    # mongoengine chokes on empty strings for fields
                    # that are not required. Clean them up here, though
                    # this is maybe not the right place :-)
                    setattr(self.instance, f.name, None)
                    # opts._dont_save.append(f.name)
        except ValidationError as e:
            err = {f.name: [e.message]}
            self._update_errors(err)

        # Call validate() on the document. Since mongoengine
        # does not provide an argument to specify which fields
        # should be excluded during validation, we replace
        # instance._fields_ordered with a version that does
        # not include excluded fields. The attribute gets
        # restored after validation.
        original_fields = self.instance._fields_ordered
        self.instance._fields_ordered = tuple(
            [f for f in original_fields if f not in exclude]
        )
        try:
            self.instance.validate()
        except __HOLE__ as e:
            if MONGO_NON_FIELD_ERRORS in e.errors:
                error = e.errors.get(MONGO_NON_FIELD_ERRORS)
            else:
                error = e.message
            self._update_errors({NON_FIELD_ERRORS: [error, ]})
        finally:
            self.instance._fields_ordered = original_fields

        # Validate uniqueness if needed.
        if self._validate_unique:
            self.validate_unique()
dataset/ETHPy150Open jschrewe/django-mongodbforms/mongodbforms/documents.py/BaseDocumentForm._post_clean