+ # 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...
+
+ sites = self.cleaned_data['sites']
+
+ existing_sites = []
+ for sdp in list(deployment.sitedeployments_set.all()):
+ if sdp.site not in sites:
+ #print "deleting site", sdp.site
+ sdp.delete()
+ else:
+ existing_sites.append(sdp.site)
+
+ for site in sites:
+ if site not in existing_sites:
+ #print "adding site", site
+ sdp = SiteDeployments(site=site, deployment=deployment)
+ sdp.save()
+