def save(self, commit=True):
        deployment = super(DeploymentAdminForm, self).save(commit=False)

        if commit:
            deployment.save()
            # this has to be done after save() if/when a deployment is first
            # created
            deployment.flavors = self.cleaned_data['flavors']

        if deployment.pk:
            # save_m2m() doesn't seem to work with 'through' relations. So we
            #    create/destroy the through models ourselves. There has to be
            #    a better way...

            self.manipulate_m2m_objs(deployment, self.cleaned_data[
                                     'images'], deployment.imagedeployments.all(), ImageDeployments, "deployment", "image")
            # manipulate_m2m_objs doesn't work for Flavor/Deployment relationship
            # so well handle that manually here
            for flavor in deployment.flavors.all():
                if getattr(flavor, 'name') not in self.cleaned_data['flavors']:
                    deployment.flavors.remove(flavor)
            for flavor in self.cleaned_data['flavors']:
                if flavor not in deployment.flavors.all():
                    flavor.deployments.add(deployment)

        self.save_m2m()

        return deployment
dataset/ETHPy150Open open-cloud/xos/xos/core/admin.py/DeploymentAdminForm.save/original