Split up TR label

This commit is contained in:
Matthew Ryan Dillon 2016-02-03 13:25:30 -07:00
parent 1edb557f91
commit c62fc40f72
3 changed files with 39 additions and 4 deletions

View file

@ -62,8 +62,8 @@ class TreatmentReplicateAdmin(admin.ModelAdmin):
class AliveDeadCountAdmin(admin.ModelAdmin): class AliveDeadCountAdmin(admin.ModelAdmin):
list_display = ('treatment_replicate', 'status_date', 'status_time', list_display = ('treatment', 'tr', 'status_date',
'count_alive', 'count_dead', 'flaw') 'status_time', 'count_alive', 'count_dead', 'flaw')
list_display_links = ('status_date',) list_display_links = ('status_date',)
search_fields = ('treatment_replicate', 'status_date', 'status_time', search_fields = ('treatment_replicate', 'status_date', 'status_time',
'count_alive', 'count_dead', 'flaw') 'count_alive', 'count_dead', 'flaw')
@ -71,6 +71,16 @@ class AliveDeadCountAdmin(admin.ModelAdmin):
fields = ('treatment_replicate', 'status_date', 'status_time', fields = ('treatment_replicate', 'status_date', 'status_time',
'count_alive', 'count_dead', 'flaw') '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(Flaw, FlawAdmin)
admin.site.register(Experiment, ExperimentAdmin) admin.site.register(Experiment, ExperimentAdmin)

View file

@ -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,
),
]

View file

@ -67,10 +67,15 @@ class Treatment(models.Model):
species = models.ForeignKey('species.Species') species = models.ForeignKey('species.Species')
sex = models.CharField(max_length=25) sex = models.CharField(max_length=25)
flaw = models.ForeignKey(Flaw, blank=True, null=True) 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): def __str__(self):
return "{} {} {} {}".format(self.treatment_type, self.study_location, return self.display_name
self.species, self.sex)
class TreatmentReplicate(models.Model): class TreatmentReplicate(models.Model):