def save_instance(self, instance, fields=None, fail_message='saved',
                      commit=True, exclude=None, construct=True):
        if construct:
            instance = construct_instance(self, instance, fields, exclude)
        opts = instance._meta
        if self.errors:
            raise ValueError("the %s could not be %s because the data didn't"
                             " validate." % (opts.object_name, fail_message))

        # wrap up the saving of m2m data as a function.
        def save_m2m(instance):
            cleaned_data = self.cleaned_data
            for f in opts.many_to_many:
                if fields and f.name not in fields:
                    continue
                if f.name in cleaned_data:
                    for validator in f.validators:
                        validator(instance, cleaned_data[f.name])
                    f.save_form_data(instance, cleaned_data[f.name])
        if commit:
            # TODO XXX, why are we not using transactions?
            # if we are committing, save the instance and the m2m data
            # immediately.
            if not instance.pk:
                rollback = True
            else:
                rollback = False
            instance.save()
            try:
                save_m2m(instance)
                # ^-- pass instance so we can validate it's views
            except ValidationError:
                if rollback:
                    self.delete_instance(instance)
                    # we didn't call ensure_label_domain so it's not our
                    # responsibility to call prune_tree
                raise
        else:
            # we're not committing. add a method to the form to allow deferred
            # saving of m2m data.
            self.save_m2m = save_m2m
        return instance
Saves bound Form ``form``'s cleaned_data into model instance
dataset/ETHPy150Open mozilla/inventory/mozdns/forms.py/BaseForm.save_instance