Treatment Replicate
This commit is contained in:
parent
a8a87f7ddb
commit
6d7242aacc
5 changed files with 80 additions and 21 deletions
|
@ -1,7 +1,7 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType, \
|
from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType, \
|
||||||
Treatment
|
Treatment, TreatmentReplicate
|
||||||
|
|
||||||
|
|
||||||
class FlawAdmin(admin.ModelAdmin):
|
class FlawAdmin(admin.ModelAdmin):
|
||||||
|
@ -50,8 +50,20 @@ class TreatmentAdmin(admin.ModelAdmin):
|
||||||
'sex', 'flaw')
|
'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(Flaw, FlawAdmin)
|
||||||
admin.site.register(Experiment, ExperimentAdmin)
|
admin.site.register(Experiment, ExperimentAdmin)
|
||||||
admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin)
|
admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin)
|
||||||
admin.site.register(TreatmentType, TreatmentTypeAdmin)
|
admin.site.register(TreatmentType, TreatmentTypeAdmin)
|
||||||
admin.site.register(Treatment, TreatmentAdmin)
|
admin.site.register(Treatment, TreatmentAdmin)
|
||||||
|
admin.site.register(TreatmentReplicate, TreatmentReplicateAdmin)
|
||||||
|
|
31
ccdb/experiments/migrations/0004_treatment_replicate.py
Normal file
31
ccdb/experiments/migrations/0004_treatment_replicate.py
Normal file
|
@ -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')]),
|
||||||
|
),
|
||||||
|
]
|
|
@ -70,3 +70,20 @@ class Treatment(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{} {} {} {}".format(self.treatment_type, self.study_location,
|
return "{} {} {} {}".format(self.treatment_type, self.study_location,
|
||||||
self.species, self.sex)
|
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')
|
||||||
|
|
|
@ -13,11 +13,12 @@ from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \
|
||||||
from ccdb.locations.models import Region, Site, MunicipalLocation, \
|
from ccdb.locations.models import Region, Site, MunicipalLocation, \
|
||||||
StudyLocation, StorageLocation
|
StudyLocation, StorageLocation
|
||||||
from ccdb.species.models import Species, CollectionSpecies
|
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, \
|
from ccdb.collections_ccdb.models import CollectionType, CollectionMethod, \
|
||||||
Flaw, ADFGPermit, Collection
|
Flaw as CollectionFlaw, ADFGPermit, Collection
|
||||||
from ccdb.experiments.models import Flaw, Experiment, ProtocolAttachment, \
|
from ccdb.experiments.models import Flaw as ExperimentFlaw, Experiment, \
|
||||||
TreatmentType, Treatment
|
ProtocolAttachment, TreatmentType, Treatment, TreatmentReplicate
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
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],
|
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])
|
study_location_id=r[3], species_id=r[4], sex=r[5])
|
||||||
t.save()
|
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()
|
||||||
|
|
|
@ -346,19 +346,3 @@ class TblSamples(models.Model):
|
||||||
managed = False
|
managed = False
|
||||||
db_table = 'tbl_Samples'
|
db_table = 'tbl_Samples'
|
||||||
unique_together = (('TrRepID', 'Sample_Date', 'Sample_Time', 'Time_Block'),)
|
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'),)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue