diff --git a/ccdb/collections_ccdb/migrations/0002_DATA_initial.py b/ccdb/collections_ccdb/migrations/0002_DATA_initial.py index b01404d..816955c 100644 --- a/ccdb/collections_ccdb/migrations/0002_DATA_initial.py +++ b/ccdb/collections_ccdb/migrations/0002_DATA_initial.py @@ -82,7 +82,8 @@ class Migration(migrations.Migration): adfg_permit=permit)) if form.is_valid(): project = Project.objects.get(id=r[0]) - d = "{}_{}_{}_{}".format(project, form.cleaned_data['collection_end_date'], + d = "{}_{}_{}_{}".format(project.name, + form.cleaned_data['collection_end_date'], form.cleaned_data['study_location'], form.cleaned_data['collection_type']) Collection.objects.create(id=r[1], display_name=d, **form.cleaned_data) diff --git a/ccdb/experiments/migrations/0001_initial.py b/ccdb/experiments/migrations/0001_initial.py index a74ddf2..0fc078c 100644 --- a/ccdb/experiments/migrations/0001_initial.py +++ b/ccdb/experiments/migrations/0001_initial.py @@ -126,6 +126,12 @@ class Migration(migrations.Migration): name='alivedeadcount', options={'verbose_name': 'Alive-dead Count'}, ), + migrations.AddField( + model_name='treatmenttype', + name='display_name', + field=models.CharField(default='x', max_length=255, editable=False), + preserve_default=False, + ), migrations.AddField( model_name='treatmentreplicate', name='display_name', diff --git a/ccdb/experiments/migrations/0002_DATA_initial.py b/ccdb/experiments/migrations/0002_DATA_initial.py index a62e7c2..2867fff 100644 --- a/ccdb/experiments/migrations/0002_DATA_initial.py +++ b/ccdb/experiments/migrations/0002_DATA_initial.py @@ -46,7 +46,11 @@ class Migration(migrations.Migration): treatment_type=r[4], placement=r[5], description=r[6])) if form.is_valid(): - TreatmentType.objects.create(id=r[1], **form.cleaned_data) + experiment = Experiment.objects.get(id=r[0]) + d = "{} {} {} {}".format(experiment.name, form.cleaned_data['name'], + form.cleaned_data['treatment_type'], + form.cleaned_data['placement']) + TreatmentType.objects.create(id=r[1], display_name=d, **form.cleaned_data) else: print('treatment type', r[0:], form.errors.as_data()) @@ -57,8 +61,10 @@ class Migration(migrations.Migration): treatment_type = TreatmentType.objects.get(id=r[1]) study_location = StudyLocation.objects.get(id=r[3]) species = Species.objects.get(id=r[4]) - d = "{}_{}_{}_{}".format(treatment_type, study_location, - species, form.cleaned_data['sex']) + d = "{}_{}_{}_{}".format(treatment_type.display_name, + study_location.code, + species.common_name, + form.cleaned_data['sex']) Treatment.objects.create(id=r[0], display_name=d, **form.cleaned_data) else: print('treatment', r[0:], form.errors.as_data()) @@ -76,7 +82,13 @@ class Migration(migrations.Migration): setup_sample_size=r[5], mass_g=r[6], flaw=flaw)) if form.is_valid(): - TreatmentReplicate.objects.create(id=r[1], **form.cleaned_data) + treatment = Treatment.objects.get(id=r[0]) + d = "{}_{}_{}_{}".format(treatment.display_name, + form.cleaned_data['setup_date'], + form.cleaned_data['name'], + form.cleaned_data['setup_sample_size']) + TreatmentReplicate.objects.create(id=r[1], display_name=d, + **form.cleaned_data) else: print('treatment replicate', r[0:], form.errors.as_data()) diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py index 9f68728..75f58cb 100644 --- a/ccdb/experiments/models.py +++ b/ccdb/experiments/models.py @@ -51,10 +51,16 @@ class TreatmentType(models.Model): description = models.CharField(max_length=255, blank=True) sort_order = models.IntegerField(blank=True, null=True) slug = AutoSlugField(populate_from='name') + display_name = models.CharField(max_length=255, editable=False) + + def save(self, *args, **kwargs): + self.display_name = "{} {} {} {}".format(self.experiment, self.name, + self.treatment_type, + self.placement) + super(TreatmentType, self).save(*args, **kwargs) def __str__(self): - return "{} {} {} {}".format(self.experiment, self.name, - self.treatment_type, self.placement) + return self.display_name class Meta: unique_together = ('experiment', 'name')