Fix up display names

This commit is contained in:
Matthew Ryan Dillon 2016-06-15 15:45:54 -07:00
parent a541a6f301
commit 65bc5c16d4
4 changed files with 32 additions and 7 deletions

View file

@ -82,7 +82,8 @@ class Migration(migrations.Migration):
adfg_permit=permit)) adfg_permit=permit))
if form.is_valid(): if form.is_valid():
project = Project.objects.get(id=r[0]) 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['study_location'],
form.cleaned_data['collection_type']) form.cleaned_data['collection_type'])
Collection.objects.create(id=r[1], display_name=d, **form.cleaned_data) Collection.objects.create(id=r[1], display_name=d, **form.cleaned_data)

View file

@ -126,6 +126,12 @@ class Migration(migrations.Migration):
name='alivedeadcount', name='alivedeadcount',
options={'verbose_name': 'Alive-dead Count'}, 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( migrations.AddField(
model_name='treatmentreplicate', model_name='treatmentreplicate',
name='display_name', name='display_name',

View file

@ -46,7 +46,11 @@ class Migration(migrations.Migration):
treatment_type=r[4], placement=r[5], treatment_type=r[4], placement=r[5],
description=r[6])) description=r[6]))
if form.is_valid(): 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: else:
print('treatment type', r[0:], form.errors.as_data()) 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]) treatment_type = TreatmentType.objects.get(id=r[1])
study_location = StudyLocation.objects.get(id=r[3]) study_location = StudyLocation.objects.get(id=r[3])
species = Species.objects.get(id=r[4]) species = Species.objects.get(id=r[4])
d = "{}_{}_{}_{}".format(treatment_type, study_location, d = "{}_{}_{}_{}".format(treatment_type.display_name,
species, form.cleaned_data['sex']) study_location.code,
species.common_name,
form.cleaned_data['sex'])
Treatment.objects.create(id=r[0], display_name=d, **form.cleaned_data) Treatment.objects.create(id=r[0], display_name=d, **form.cleaned_data)
else: else:
print('treatment', r[0:], form.errors.as_data()) 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], setup_sample_size=r[5], mass_g=r[6],
flaw=flaw)) flaw=flaw))
if form.is_valid(): 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: else:
print('treatment replicate', r[0:], form.errors.as_data()) print('treatment replicate', r[0:], form.errors.as_data())

View file

@ -51,10 +51,16 @@ class TreatmentType(models.Model):
description = models.CharField(max_length=255, blank=True) description = models.CharField(max_length=255, blank=True)
sort_order = models.IntegerField(blank=True, null=True) sort_order = models.IntegerField(blank=True, null=True)
slug = AutoSlugField(populate_from='name') 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): def __str__(self):
return "{} {} {} {}".format(self.experiment, self.name, return self.display_name
self.treatment_type, self.placement)
class Meta: class Meta:
unique_together = ('experiment', 'name') unique_together = ('experiment', 'name')