def to_object(self): if hasattr(self, 'object') and self.object: return self.object d = self.object_dict n = Need() for attr in ['creator', 'description']: setattr(n, attr, d[attr]) # TODO: migrate title attribute to name n.title = d['name'] n.save() # m2m relationships n.community = d['community'] n.categories = d['categories'] n.tags.add(*d['tags']) n.target_audiences = [TargetAudience.objects.get_or_create(name=ta)[0]\ for ta in d['target_audiences']] if 'geometry' in d: n.geometry = d['geometry'] n.save() self.object = n return n