From 8114bb9f2c9b89695ab79544d3c5a6cb11471c2a Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 1 Feb 2016 15:28:02 -0700 Subject: [PATCH] Experiment-Collection --- ccdb/experiments/admin.py | 2 +- .../migrations/0006_experiment_collections.py | 20 +++++++++++++++++++ ccdb/experiments/models.py | 1 + ccdb/utils/management/commands/import_data.py | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ccdb/experiments/migrations/0006_experiment_collections.py diff --git a/ccdb/experiments/admin.py b/ccdb/experiments/admin.py index ebcb44a..215fdb8 100644 --- a/ccdb/experiments/admin.py +++ b/ccdb/experiments/admin.py @@ -17,7 +17,7 @@ class ExperimentAdmin(admin.ModelAdmin): list_display_links = ('name',) search_fields = ('name', 'code', 'description', 'flaw', 'sort_order') list_per_page = 25 - fields = ('name', 'code', 'description', 'flaw', 'sort_order') + fields = ('name', 'code', 'description', 'flaw', 'collections', 'sort_order') class ProtocolAttachmentAdmin(admin.ModelAdmin): diff --git a/ccdb/experiments/migrations/0006_experiment_collections.py b/ccdb/experiments/migrations/0006_experiment_collections.py new file mode 100644 index 0000000..5bf2293 --- /dev/null +++ b/ccdb/experiments/migrations/0006_experiment_collections.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('collections_ccdb', '0001_initial'), + ('experiments', '0005_alivedeadcount'), + ] + + operations = [ + migrations.AddField( + model_name='experiment', + name='collections', + field=models.ManyToManyField(to='collections_ccdb.Collection'), + ), + ] diff --git a/ccdb/experiments/models.py b/ccdb/experiments/models.py index 9822c66..6ae8b29 100644 --- a/ccdb/experiments/models.py +++ b/ccdb/experiments/models.py @@ -23,6 +23,7 @@ class Experiment(models.Model): flaw = models.ForeignKey(Flaw, blank=True, null=True) sort_order = models.IntegerField(blank=True, null=True) slug = AutoSlugField(populate_from='name') + collections = models.ManyToManyField('collections_ccdb.Collection') def __str__(self): return self.name diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 307dadd..4f376a8 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -269,3 +269,10 @@ def _import_admin_data(): status_date=r[12], status_time=r[13], count_alive=r[4], count_dead=r[5], flaw=flaw) adc.save() + + # Experiment-Collection + for r in c.execute('SELECT * FROM tbl_hash_collection_experiments;'): + c = Collection.objects.get(id=r[0]) + e = Experiment.objects.get(id=r[1]) + e.collections.add(c) + e.save()