diff --git a/ccdb/experiments/admin.py b/ccdb/experiments/admin.py index 2fb1ce6..1f98947 100644 --- a/ccdb/experiments/admin.py +++ b/ccdb/experiments/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType, \ - Treatment + Treatment, TreatmentReplicate class FlawAdmin(admin.ModelAdmin): @@ -50,8 +50,20 @@ class TreatmentAdmin(admin.ModelAdmin): 'sex', 'flaw') +class TreatmentReplicateAdmin(admin.ModelAdmin): + list_display = ('treatment', 'name', 'setup_date', 'setup_time', + 'setup_sample_size', 'mass_g', 'flaw') + list_display_links = ('name',) + search_fields = ('treatment', 'name', 'setup_date', 'setup_time', + 'setup_sample_size', 'mass_g', 'flaw') + list_per_page = 25 + fields = ('treatment', 'name', 'setup_date', 'setup_time', + 'setup_sample_size', 'mass_g', 'flaw') + + admin.site.register(Flaw, FlawAdmin) admin.site.register(Experiment, ExperimentAdmin) admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin) admin.site.register(TreatmentType, TreatmentTypeAdmin) admin.site.register(Treatment, TreatmentAdmin) +admin.site.register(TreatmentReplicate, TreatmentReplicateAdmin) diff --git a/ccdb/experiments/migrations/0004_treatment_replicate.py b/ccdb/experiments/migrations/0004_treatment_replicate.py new file mode 100644 index 0000000..40fe20e --- /dev/null +++ b/ccdb/experiments/migrations/0004_treatment_replicate.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('experiments', '0003_treatment'), + ] + + operations = [ + migrations.CreateModel( + name='TreatmentReplicate', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=50)), + ('setup_date', models.DateField(null=True, blank=True)), + ('setup_time', models.TimeField(null=True, blank=True)), + ('setup_sample_size', models.IntegerField(null=True, blank=True)), + ('mass_g', models.FloatField(null=True, blank=True)), + ('flaw', models.ForeignKey(null=True, to='experiments.Flaw', blank=True)), + ('treatment', models.ForeignKey(to='experiments.Treatment')), + ], + ), + migrations.AlterUniqueTogether( + name='treatmentreplicate', + unique_together=set([('treatment', 'name', 'setup_date', 'setup_time')]), + ), + ] diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py index 746464b..10f29b4 100644 --- a/ccdb/experiments/models.py +++ b/ccdb/experiments/models.py @@ -70,3 +70,20 @@ class Treatment(models.Model): def __str__(self): return "{} {} {} {}".format(self.treatment_type, self.study_location, self.species, self.sex) + + +class TreatmentReplicate(models.Model): + treatment = models.ForeignKey(Treatment) + name = models.CharField(max_length=50) + setup_date = models.DateField(blank=True, null=True) + setup_time = models.TimeField(blank=True, null=True) + setup_sample_size = models.IntegerField(blank=True, null=True) + mass_g = models.FloatField(blank=True, null=True) + flaw = models.ForeignKey(Flaw, blank=True, null=True) + + def __str__(self): + return "{} {} {} {}".format(self.treatment, self.name, + self.setup_date, self.setup_sample_size) + + class Meta: + unique_together = ('treatment', 'name', 'setup_date', 'setup_time') diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 55d8e20..1535faf 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -13,11 +13,12 @@ from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \ from ccdb.locations.models import Region, Site, MunicipalLocation, \ StudyLocation, StorageLocation from ccdb.species.models import Species, CollectionSpecies -from ccdb.processing.models import ProcessType, Reagent, Flaw, Processing +from ccdb.processing.models import ProcessType, Reagent, \ + Flaw as ProcessingFlaw,Processing from ccdb.collections_ccdb.models import CollectionType, CollectionMethod, \ - Flaw, ADFGPermit, Collection -from ccdb.experiments.models import Flaw, Experiment, ProtocolAttachment, \ - TreatmentType, Treatment + Flaw as CollectionFlaw, ADFGPermit, Collection +from ccdb.experiments.models import Flaw as ExperimentFlaw, Experiment, \ + ProtocolAttachment, TreatmentType, Treatment, TreatmentReplicate class Command(BaseCommand): @@ -236,3 +237,17 @@ def _import_admin_data(): t = Treatment(id=r[0], treatment_type_id=r[1], container_id=r[2], study_location_id=r[3], species_id=r[4], sex=r[5]) t.save() + + # Treatment Replicate + for r in c.execute(''' + SELECT *, setup_date AS "setup_date [dtdt]" + FROM tbl_treatment_replicates tr + INNER JOIN tbl_lu_record_flaws f ON f.flawid=tr.flawid; + '''): + if r[10] is not '': + flaw, _ = ExperimentFlaw.objects.get_or_create(name=r[10]) + else: + flaw = None + tr = TreatmentReplicate(treatment_id=r[0], id=r[1], name=r[2], + setup_date=r[13], setup_sample_size=r[5], mass_g=r[6], flaw=flaw) + tr.save() diff --git a/misc/existing.py b/misc/existing.py index 3ff3780..82feeb2 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -346,19 +346,3 @@ class TblSamples(models.Model): managed = False db_table = 'tbl_Samples' unique_together = (('TrRepID', 'Sample_Date', 'Sample_Time', 'Time_Block'),) - - -class TblTreatmentReplicates(models.Model): - treatmentid = models.ForeignKey('TblTreatments', db_column='TreatmentID') # Field name made lowercase. - trrepid = models.AutoField(db_column='TrRepID', primary_key=True) # Field name made lowercase. - replicate = models.CharField(db_column='Replicate', max_length=50) # Field name made lowercase. - setup_date = models.DateField(db_column='Setup_Date', blank=True, null=True) # Field name made lowercase. - setup_time = models.TimeField(db_column='Setup_Time', blank=True, null=True) # Field name made lowercase. - setup_sample_size = models.IntegerField(db_column='Setup_Sample_Size', blank=True, null=True) # Field name made lowercase. - mass_g = models.FloatField(db_column='Mass_g', blank=True, null=True) # Field name made lowercase. - flawid = models.ForeignKey(TblLuRecordFlaws, db_column='FlawID', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_Treatment_Replicates' - unique_together = (('TreatmentID', 'Replicate', 'Setup_Date', 'Setup_Time'),)