diff --git a/ccdb/experiments/__init__.py b/ccdb/experiments/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/experiments/admin.py b/ccdb/experiments/admin.py new file mode 100644 index 0000000..0e106ae --- /dev/null +++ b/ccdb/experiments/admin.py @@ -0,0 +1,32 @@ +from django.contrib import admin + +from .models import Flaw, Experiment, ProtocolAttachment + + +class FlawAdmin(admin.ModelAdmin): + list_display = ('name', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'description') + list_per_page = 25 + fields = ('name', 'description') + + +class ExperimentAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'description', 'flaw', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'description', 'flaw', 'sort_order') + list_per_page = 25 + fields = ('name', 'code', 'description', 'flaw', 'sort_order') + + +class ProtocolAttachmentAdmin(admin.ModelAdmin): + list_display = ('experiment', 'protocol') + list_display_links = ('protocol',) + search_fields = ('protocol',) + list_per_page = 25 + fields = ('experiment', 'protocol') + + +admin.site.register(Flaw, FlawAdmin) +admin.site.register(Experiment, ExperimentAdmin) +admin.site.register(ProtocolAttachment, ProtocolAttachmentAdmin) diff --git a/ccdb/experiments/migrations/0001_initial.py b/ccdb/experiments/migrations/0001_initial.py new file mode 100644 index 0000000..830cc70 --- /dev/null +++ b/ccdb/experiments/migrations/0001_initial.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import autoslug.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Experiment', + fields=[ + ('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)), + ('name', models.CharField(max_length=150)), + ('code', models.CharField(max_length=10, blank=True)), + ('description', models.CharField(max_length=255, blank=True)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='Flaw', + fields=[ + ('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)), + ('name', models.CharField(max_length=200)), + ('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'], + }, + ), + migrations.CreateModel( + name='ProtocolAttachment', + fields=[ + ('id', models.AutoField(auto_created=True, serialize=False, verbose_name='ID', primary_key=True)), + ('protocol', models.FileField(upload_to='experiments/protocols/%Y/%m/%d')), + ('experiment', models.ForeignKey(to='experiments.Experiment')), + ], + ), + migrations.AddField( + model_name='experiment', + name='flaw', + field=models.ForeignKey(to='experiments.Flaw', null=True, blank=True), + ), + migrations.AlterUniqueTogether( + name='experiment', + unique_together=set([('name', 'code')]), + ), + ] diff --git a/ccdb/experiments/migrations/__init__.py b/ccdb/experiments/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py new file mode 100644 index 0000000..f98c49c --- /dev/null +++ b/ccdb/experiments/models.py @@ -0,0 +1,39 @@ +from django.db import models + +from autoslug import AutoSlugField + + +class Flaw(models.Model): + name = models.CharField(max_length=200) + 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: + ordering = ['sort_order'] + + +class Experiment(models.Model): + name = models.CharField(max_length=150) + code = models.CharField(max_length=10, blank=True) + description = models.CharField(max_length=255, blank=True) + flaw = models.ForeignKey(Flaw, blank=True, null=True) + sort_order = models.IntegerField(blank=True, null=True) + + def __str__(self): + return self.name + + class Meta: + unique_together = ('name', 'code') + ordering = ['sort_order'] + + +class ProtocolAttachment(models.Model): + experiment = models.ForeignKey(Experiment) + protocol = models.FileField(upload_to='experiments/protocols/%Y/%m/%d') + + def __str__(self): + return self.protocol diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index b2385d0..15a0e3d 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -16,6 +16,7 @@ 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 class Command(BaseCommand): @@ -216,3 +217,9 @@ def _import_admin_data(): cs.save() except IntegrityError: pass + + # Experiment + for r in c.execute('SELECT * FROM tbl_lu_experiments;'): + e = Experiment(id=r[0], name=r[1], code=r[2], + description=r[3], sort_order=r[6]) + e.save() diff --git a/config/settings/base.py b/config/settings/base.py index bff0974..d2e9dc8 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -45,6 +45,7 @@ LOCAL_APPS = ( 'ccdb.species', 'ccdb.collections_ccdb', 'ccdb.processing', + 'ccdb.experiments', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/misc/existing.py b/misc/existing.py index 66cebb7..9a84114 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -263,21 +263,6 @@ class TblLuCommentTypes(models.Model): unique_together = (('Comment_Type', 'Comment_Type_Code'),) -class TblLuExperiments(models.Model): - experimentid = models.AutoField(db_column='ExperimentID', primary_key=True) # Field name made lowercase. - experiment_name = models.CharField(db_column='Experiment_Name', max_length=150) # Field name made lowercase. - experiment_code = models.CharField(db_column='Experiment_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - experiment_short_description = models.CharField(db_column='Experiment_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. - link_to_protocol = models.CharField(db_column='Link_To_Protocol', max_length=255, blank=True, null=True) # Field name made lowercase. - flawid = models.ForeignKey('TblLuRecordFlaws', db_column='FlawID', 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_Experiments' - unique_together = (('Experiment_Name', 'Experiment_Code'),) - - class TblLuPeople(models.Model): peopleid = models.AutoField(db_column='PeopleID', primary_key=True) # Field name made lowercase. affiliationid = models.ForeignKey(TblLuAffiliations, db_column='AffiliationID', blank=True, null=True) # Field name made lowercase.