From ab1d605c95ae4b621d306c75c21b33772163dd71 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 1 Feb 2016 14:30:19 -0700 Subject: [PATCH] Treatment Type --- ccdb/experiments/admin.py | 14 +++++++- ccdb/experiments/migrations/0001_initial.py | 1 + .../migrations/0002_treatment_type.py | 36 +++++++++++++++++++ ccdb/experiments/models.py | 19 ++++++++++ ccdb/utils/management/commands/import_data.py | 9 ++++- misc/existing.py | 16 --------- 6 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 ccdb/experiments/migrations/0002_treatment_type.py diff --git a/ccdb/experiments/admin.py b/ccdb/experiments/admin.py index 0e106ae..06d657a 100644 --- a/ccdb/experiments/admin.py +++ b/ccdb/experiments/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Flaw, Experiment, ProtocolAttachment +from .models import Flaw, Experiment, ProtocolAttachment, TreatmentType class FlawAdmin(admin.ModelAdmin): @@ -27,6 +27,18 @@ class ProtocolAttachmentAdmin(admin.ModelAdmin): fields = ('experiment', 'protocol') +class TreatmentTypeAdmin(admin.ModelAdmin): + list_display = ('experiment', 'name', 'code', 'treatment_type', + 'placement', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('experiment', 'name', 'code', 'treatment_type', + 'placement', 'description') + list_per_page = 25 + fields = ('experiment', 'name', 'code', 'treatment_type', 'placement', + 'description', 'sort_order') + + admin.site.register(Flaw, FlawAdmin) admin.site.register(Experiment, ExperimentAdmin) admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin) +admin.site.register(TreatmentType, TreatmentTypeAdmin) diff --git a/ccdb/experiments/migrations/0001_initial.py b/ccdb/experiments/migrations/0001_initial.py index 830cc70..c528c95 100644 --- a/ccdb/experiments/migrations/0001_initial.py +++ b/ccdb/experiments/migrations/0001_initial.py @@ -19,6 +19,7 @@ class Migration(migrations.Migration): ('code', models.CharField(max_length=10, blank=True)), ('description', models.CharField(max_length=255, blank=True)), ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), ], options={ 'ordering': ['sort_order'], diff --git a/ccdb/experiments/migrations/0002_treatment_type.py b/ccdb/experiments/migrations/0002_treatment_type.py new file mode 100644 index 0000000..f1d050a --- /dev/null +++ b/ccdb/experiments/migrations/0002_treatment_type.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import autoslug.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('experiments', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='TreatmentType', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('name', models.CharField(max_length=200)), + ('code', models.CharField(max_length=25, blank=True)), + ('treatment_type', models.CharField(max_length=50, blank=True)), + ('placement', models.CharField(max_length=25, blank=True)), + ('description', models.CharField(max_length=255, blank=True)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), + ('experiment', models.ForeignKey(null=True, blank=True, to='experiments.Experiment')), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.AlterUniqueTogether( + name='treatmenttype', + unique_together=set([('experiment', 'name')]), + ), + ] diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py index f98c49c..27d36ea 100644 --- a/ccdb/experiments/models.py +++ b/ccdb/experiments/models.py @@ -22,6 +22,7 @@ class Experiment(models.Model): description = models.CharField(max_length=255, blank=True) flaw = models.ForeignKey(Flaw, blank=True, null=True) sort_order = models.IntegerField(blank=True, null=True) + slug = AutoSlugField(populate_from='name') def __str__(self): return self.name @@ -37,3 +38,21 @@ class ProtocolAttachment(models.Model): def __str__(self): return self.protocol + + +class TreatmentType(models.Model): + experiment = models.ForeignKey(Experiment, blank=True, null=True) + name = models.CharField(max_length=200) + code = models.CharField(max_length=25, blank=True) + treatment_type = models.CharField(max_length=50, blank=True) + placement = models.CharField(max_length=25, blank=True) + description = models.CharField(max_length=255, blank=True) + sort_order = models.IntegerField(blank=True, null=True) + slug = AutoSlugField(populate_from='name') + + def __str__(self): + return self.name + + class Meta: + unique_together = ('experiment', 'name') + ordering = ['sort_order'] diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 15a0e3d..341177c 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -16,7 +16,8 @@ from ccdb.species.models import Species, CollectionSpecies from ccdb.processing.models import ProcessType, Reagent, Flaw, Processing from ccdb.collections_ccdb.models import CollectionType, CollectionMethod, \ Flaw, ADFGPermit, Collection -from ccdb.experiments.models import Flaw, Experiment, ProtocolAttachment +from ccdb.experiments.models import Flaw, Experiment, ProtocolAttachment, \ + TreatmentType class Command(BaseCommand): @@ -223,3 +224,9 @@ def _import_admin_data(): e = Experiment(id=r[0], name=r[1], code=r[2], description=r[3], sort_order=r[6]) e.save() + + # Treatment Type + for r in c.execute('SELECT * FROM tbl_lu_treatment_types;'): + tt = TreatmentType(experiment_id=r[0], id=r[1], name=r[2], code=r[3], + treatment_type=r[4], placement=r[5], description=r[6]) + tt.save() diff --git a/misc/existing.py b/misc/existing.py index 9a84114..e6d4633 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -315,22 +315,6 @@ class TblLuSampleTypes(models.Model): unique_together = (('Sample_Type', 'Sample_Type_Code'),) -class TblLuTreatmentTypes(models.Model): - treatment_typeid = models.AutoField(db_column='Treatment_TypeID', primary_key=True) # Field name made lowercase. - experimentid = models.ForeignKey(TblLuExperiments, db_column='ExperimentID', blank=True, null=True) # Field name made lowercase. - treatment = models.CharField(db_column='Treatment', max_length=200) # Field name made lowercase. - treatment_code = models.CharField(db_column='Treatment_Code', max_length=25, blank=True, null=True) # Field name made lowercase. - treatment_type = models.CharField(db_column='Treatment_Type', max_length=50, blank=True, null=True) # Field name made lowercase. - placement = models.CharField(db_column='Placement', max_length=25, blank=True, null=True) # Field name made lowercase. - treatment_short_description = models.CharField(db_column='Treatment_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. - sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_LU_Treatment_Types' - unique_together = (('ExperimentID', 'Treatment'),) - - class TblLuUsers(models.Model): userid = models.AutoField(db_column='UserID', primary_key=True) # Field name made lowercase. first_name = models.CharField(db_column='First_Name', max_length=50) # Field name made lowercase.