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)
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)
# 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(""" SELECT cardable_id, users.id AS user_id, affiliations, enabled, vcards.id, n_family, n_given, n_prefix, n_suffix, cardable_type, email FROM vcards LEFT JOIN users ON vcards.cardable_id = users.id AND cardable_type = 'User' ORDER BY cardable_type """) for row in dictfetchall(old): user = User.objects.filter(email=row['email']).first() if not user: user = User(email=row['email'], is_active=False)