From c62fc40f725d5a6fddf80a3b5509ff0a3da53ad4 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 3 Feb 2016 13:25:30 -0700 Subject: [PATCH] Split up TR label --- ccdb/experiments/admin.py | 14 +++++++++++-- .../migrations/0008_treatment_display_name.py | 20 +++++++++++++++++++ ccdb/experiments/models.py | 9 +++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 ccdb/experiments/migrations/0008_treatment_display_name.py diff --git a/ccdb/experiments/admin.py b/ccdb/experiments/admin.py index 215fdb8..efdc4a3 100644 --- a/ccdb/experiments/admin.py +++ b/ccdb/experiments/admin.py @@ -62,8 +62,8 @@ class TreatmentReplicateAdmin(admin.ModelAdmin): class AliveDeadCountAdmin(admin.ModelAdmin): - list_display = ('treatment_replicate', 'status_date', 'status_time', - 'count_alive', 'count_dead', 'flaw') + list_display = ('treatment', 'tr', 'status_date', + 'status_time', 'count_alive', 'count_dead', 'flaw') list_display_links = ('status_date',) search_fields = ('treatment_replicate', 'status_date', 'status_time', 'count_alive', 'count_dead', 'flaw') @@ -71,6 +71,16 @@ class AliveDeadCountAdmin(admin.ModelAdmin): fields = ('treatment_replicate', 'status_date', 'status_time', 'count_alive', 'count_dead', 'flaw') + def treatment(self, obj): + return obj.treatment_replicate.treatment + treatment.admin_order_field = 'treatment_replicate__treatment' + + def tr(self, obj): + return "{}_{}_{}".format(obj.treatment_replicate.setup_date, + obj.treatment_replicate.name, + obj.treatment_replicate.setup_sample_size) + tr.short_description = 'Treatment Replicate' + admin.site.register(Flaw, FlawAdmin) admin.site.register(Experiment, ExperimentAdmin) diff --git a/ccdb/experiments/migrations/0008_treatment_display_name.py b/ccdb/experiments/migrations/0008_treatment_display_name.py new file mode 100644 index 0000000..7323a87 --- /dev/null +++ b/ccdb/experiments/migrations/0008_treatment_display_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('experiments', '0007_treatment_replicates_display'), + ] + + operations = [ + migrations.AddField( + model_name='treatment', + name='display_name', + field=models.CharField(editable=False, default='x', max_length=255), + preserve_default=False, + ), + ] diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py index e981ffb..e2934ee 100644 --- a/ccdb/experiments/models.py +++ b/ccdb/experiments/models.py @@ -67,10 +67,15 @@ class Treatment(models.Model): species = models.ForeignKey('species.Species') sex = models.CharField(max_length=25) flaw = models.ForeignKey(Flaw, blank=True, null=True) + display_name = models.CharField(max_length=255, editable=False) + + def save(self, *args, **kwargs): + self.display_name = "{}_{}_{}_{}".format(self.treatment_type, + self.study_location, self.species, self.sex) + super(Treatment, self).save(*args, **kwargs) def __str__(self): - return "{} {} {} {}".format(self.treatment_type, self.study_location, - self.species, self.sex) + return self.display_name class TreatmentReplicate(models.Model):