def save(self, *args, **kwargs): new_species = self.cleaned_data.get("new_species") severity = self.cleaned_data.get("severity") if new_species: species = Species(name=new_species, severity=severity, category=self.cleaned_data['category']) species.save() self.instance.actual_species = species elif not self.cleaned_data.get("actual_species"): self.instance.actual_species = None return super().save(*args, **kwargs)
from hotline.reports.models import Report from hotline.species.models import Species from hotline.users.models import User old = connections['old'].cursor() # the severity ID and category IDs are assumed to be the same, so we aren't # importing those # import the species old.execute("SELECT id, category_id, severity_id, name_sci, name_comm, remedy, resources FROM issues") for row in dictfetchall(old): species = Species.objects.filter(pk=row['id']).first() if not species: species = Species(pk=row['id']) species.name = row['name_comm'] or "" species.scientific_name = row['name_sci'] or "" species.remedy = row['remedy'] or "" species.resources = row['resources'] or "" species.severity_id = row['severity_id'] species.category_id = row['category_id'] species.save() with suspended_updates(): # create users user_id_to_user_id = {} report_submitter_user_id = {} key_to_user_id = {} old.execute("""