Finish up collections admin

This commit is contained in:
Matthew Ryan Dillon 2016-02-01 13:04:51 -07:00
parent 60601beacb
commit 2c8681217b
7 changed files with 361 additions and 68 deletions

View file

@ -0,0 +1 @@
default_app_config = 'ccdb.collections_ccdb.apps.CollectionsAppConfig'

View file

@ -1,3 +1,60 @@
from django.contrib import admin
# Register your models here.
from .models import CollectionType, CollectionMethod, Flaw, ADFGPermit, \
DatasheetAttachment, CollectionTrap
class CollectionTypeAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code')
list_per_page = 25
fields = ('name', 'code', 'sort_order')
class CollectionMethodAdmin(admin.ModelAdmin):
list_display = ('name', 'code', 'collection_method_class', 'sort_order')
list_display_links = ('name',)
search_fields = ('name', 'code', 'collection_method_class')
list_per_page = 25
fields = ('name', 'code', 'collection_method_class', 'sort_order')
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 ADFGPermitAdmin(admin.ModelAdmin):
list_display = ('name', 'sort_order')
list_display_links = ('name',)
search_fields = ('name',)
list_per_page = 25
fields = ('name', 'sort_order')
class DatasheetAttachmentAdmin(admin.ModelAdmin):
list_display = ('collection', 'datasheet')
list_display_links = ('datasheet',)
list_per_page = 25
fields = ('collection', 'datasheet')
class CollectionTrapAdmin(admin.ModelAdmin):
list_display = ('collection', 'number_of_traps', 'date_opened',
'time_opened', 'date_closed', 'time_closed')
list_display_links = ('number_of_traps',)
list_per_page = 25
fields = ('collection', 'number_of_traps', 'date_opened',
'time_opened', 'date_closed', 'time_closed')
admin.site.register(CollectionType, CollectionTypeAdmin)
admin.site.register(CollectionMethod, CollectionMethodAdmin)
admin.site.register(Flaw, FlawAdmin)
admin.site.register(ADFGPermit, ADFGPermitAdmin)
admin.site.register(DatasheetAttachment, DatasheetAttachmentAdmin)
admin.site.register(CollectionTrap, CollectionTrapAdmin)

View file

@ -0,0 +1,7 @@
from django.apps import AppConfig
# This is needed because 'collections' is part of the Python Std Lib
class CollectionsAppConfig(AppConfig):
name = 'ccdb.collections_ccdb'
verbose_name = 'Collections'

View file

@ -0,0 +1,158 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import autoslug.fields
class Migration(migrations.Migration):
dependencies = [
('locations', '0002_remove_site_fk_dupes'),
('projects', '0004_initial_grantreport'),
('processing', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='ADFGPermit',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=200)),
('sort_order', models.IntegerField(null=True, blank=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')),
],
options={
'ordering': ['sort_order'],
},
),
migrations.CreateModel(
name='Collection',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('number_of_traps', models.IntegerField(null=True, blank=True)),
('collection_start_date', models.DateField(null=True, blank=True)),
('collection_start_time', models.TimeField(null=True, blank=True)),
('collection_end_date', models.DateField(null=True, blank=True)),
('collection_end_time', models.TimeField(null=True, blank=True)),
('specimen_state', models.CharField(max_length=50, blank=True)),
('adfg_permit', models.ForeignKey(to='collections_ccdb.ADFGPermit', blank=True, null=True)),
],
),
migrations.CreateModel(
name='CollectionMethod',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=100)),
('code', models.CharField(max_length=10, blank=True)),
('collection_method_class', models.CharField(max_length=50, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')),
],
options={
'ordering': ['sort_order'],
},
),
migrations.CreateModel(
name='CollectionTrap',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('number_of_traps', models.IntegerField()),
('date_opened', models.DateField()),
('time_opened', models.TimeField()),
('date_closed', models.DateField()),
('time_closed', models.TimeField()),
('collection', models.ForeignKey(to='collections_ccdb.Collection')),
],
),
migrations.CreateModel(
name='CollectionType',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=100)),
('code', models.CharField(max_length=10, blank=True)),
('sort_order', models.IntegerField(null=True, blank=True)),
('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')),
],
options={
'ordering': ['sort_order'],
},
),
migrations.CreateModel(
name='DatasheetAttachment',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('datasheet', models.FileField(verbose_name='Datasheet', upload_to='collections/datasheets/%Y/%m/%d')),
('collection', models.ForeignKey(to='collections_ccdb.Collection')),
],
),
migrations.CreateModel(
name='Flaw',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=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(editable=False, populate_from='name')),
],
options={
'ordering': ['sort_order'],
},
),
migrations.AlterUniqueTogether(
name='collectiontype',
unique_together=set([('name', 'code')]),
),
migrations.AlterUniqueTogether(
name='collectionmethod',
unique_together=set([('name', 'code')]),
),
migrations.AddField(
model_name='collection',
name='collection_method',
field=models.ForeignKey(to='collections_ccdb.CollectionMethod'),
),
migrations.AddField(
model_name='collection',
name='collection_type',
field=models.ForeignKey(to='collections_ccdb.CollectionType'),
),
migrations.AddField(
model_name='collection',
name='flaw',
field=models.ForeignKey(to='collections_ccdb.Flaw', blank=True, null=True),
),
migrations.AddField(
model_name='collection',
name='process_type',
field=models.ForeignKey(to='processing.ProcessType', blank=True, null=True),
),
migrations.AddField(
model_name='collection',
name='project',
field=models.ForeignKey(to='projects.Project'),
),
migrations.AddField(
model_name='collection',
name='reagent',
field=models.ForeignKey(to='processing.Reagent', blank=True, null=True),
),
migrations.AddField(
model_name='collection',
name='storage_location',
field=models.ForeignKey(to='locations.StorageLocation', blank=True, null=True),
),
migrations.AddField(
model_name='collection',
name='study_location',
field=models.ForeignKey(to='locations.StudyLocation'),
),
migrations.AlterUniqueTogether(
name='collectiontrap',
unique_together=set([('collection', 'date_opened', 'time_opened', 'date_closed', 'time_closed')]),
),
migrations.AlterUniqueTogether(
name='collection',
unique_together=set([('project', 'study_location', 'collection_type', 'collection_start_date', 'collection_end_date', 'collection_method')]),
),
]

View file

@ -3,27 +3,103 @@ from django.db import models
from autoslug import AutoSlugField
# class Collection(models.Model):
# project = models.ForeignKey('projects.Project')
# study_location = models.ForeignKey('locations.StudyLocation')
# collection_type = models.ForeignKey(CollectionType)
# collection_method = models.ForeignKey(CollectionMethod)
# number_of_traps = models.IntegerField(blank=True, null=True)
# collection_start_date = models.DateField(blank=True, null=True)
# collection_start_time = models.TimeField(blank=True, null=True)
# collection_end_date = models.DateField(blank=True, null=True)
# collection_end_time = models.TimeField(blank=True, null=True)
# storage_location = models.ForeignKey('locations.StorageLocation', blank=True, null=True)
# specimen_state = models.CharField(max_length=50, blank=True)
# process_type = models.ForeignKey('processing.ProcessType', blank=True, null=True)
# reagent = models.ForeignKey('processing.Reagent', blank=True, null=True)
# # adfg_permit = models.CharField(db_column='ADFG_Permit', max_length=25, blank=True, null=True) # Field name made lowercase.
# # link_to_datasheets = models.CharField(db_column='Link_To_Datasheets', max_length=255, blank=True, null=True) # Field name made lowercase.
# flaw = models.ForeignKey(Flaw, blank=True, null=True)
#
# def __str__(self):
# return "{project} {study_location} {collection_type} {collection_method}".format(**self)
#
# class Meta:
# unique_together = ('project', 'study_location', 'collection_type',
# 'collection_start_date', 'collection_end_date', 'collection_method')
class CollectionType(models.Model):
name = models.CharField(max_length=100)
code = models.CharField(max_length=10, 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 = ('name', 'code')
ordering = ['sort_order']
class CollectionMethod(models.Model):
name = models.CharField(max_length=100)
code = models.CharField(max_length=10, blank=True)
collection_method_class = models.CharField(max_length=50, 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 = ('name', 'code')
ordering = ['sort_order']
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 ADFGPermit(models.Model):
name = models.CharField(max_length=200)
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 Collection(models.Model):
project = models.ForeignKey('projects.Project')
study_location = models.ForeignKey('locations.StudyLocation')
collection_type = models.ForeignKey(CollectionType)
collection_method = models.ForeignKey(CollectionMethod)
number_of_traps = models.IntegerField(blank=True, null=True)
collection_start_date = models.DateField(blank=True, null=True)
collection_start_time = models.TimeField(blank=True, null=True)
collection_end_date = models.DateField(blank=True, null=True)
collection_end_time = models.TimeField(blank=True, null=True)
storage_location = models.ForeignKey('locations.StorageLocation', blank=True, null=True)
specimen_state = models.CharField(max_length=50, blank=True)
process_type = models.ForeignKey('processing.ProcessType', blank=True, null=True)
reagent = models.ForeignKey('processing.Reagent', blank=True, null=True)
adfg_permit = models.ForeignKey(ADFGPermit, blank=True, null=True)
flaw = models.ForeignKey(Flaw, blank=True, null=True)
def __str__(self):
return "{} {} {} {} {} {}".format(self.project, self.study_location,
self.collection_start_date, self.collection_end_date,
self.collection_type, self.collection_method)
class Meta:
unique_together = ('project', 'study_location', 'collection_type',
'collection_start_date', 'collection_end_date', 'collection_method')
class DatasheetAttachment(models.Model):
collection = models.ForeignKey(Collection)
datasheet = models.FileField("Datasheet",
upload_to='collections/datasheets/%Y/%m/%d')
class CollectionTrap(models.Model):
collection = models.ForeignKey(Collection)
number_of_traps = models.IntegerField()
date_opened = models.DateField()
time_opened = models.TimeField()
date_closed = models.DateField()
time_closed = models.TimeField()
def __str__(self):
return "{collection} {number_of_traps} {date_opened} {date_closed}".format(self)
class Meta:
unique_together = ('collection', 'date_opened', 'time_opened', 'date_closed', 'time_closed')

View file

@ -14,6 +14,8 @@ from ccdb.locations.models import Region, Site, MunicipalLocation, \
StudyLocation, StorageLocation
from ccdb.species.models import Species
from ccdb.processing.models import ProcessType, Reagent, Flaw, Processing
from ccdb.collections_ccdb.models import CollectionType, CollectionMethod, \
Flaw, ADFGPermit, Collection
class Command(BaseCommand):
@ -168,6 +170,39 @@ def _import_admin_data():
# Reagent
for r in c.execute('SELECT * FROM tbl_lu_reagents;'):
r = Reagent(id=r[0], name=r[1], code=r[2], reagent_class=r[3],
rg = Reagent(id=r[0], name=r[1], code=r[2], reagent_class=r[3],
sort_order=r[4])
r.save()
rg.save()
# Collection Type
for r in c.execute('SELECT * FROM tbl_lu_collection_types;'):
ct = CollectionType(id=r[0], name=r[1], code=r[2], sort_order=r[3])
ct.save()
# Collection Method
for r in c.execute('SELECT * FROM tbl_lu_collection_methods;'):
cm = CollectionMethod(id=r[0], name=r[1], code=r[2],
collection_method_class=r[3], sort_order=r[4])
cm.save()
# Collection
for r in c.execute('''
SELECT *,
collection_start_date AS "collection_start_date [dtdt]",
collection_start_time AS "collection_start_time [dtdt]",
collection_end_date AS "collection_end_date [dtdt]",
collection_end_time AS "collection_end_time [dtdt]"
FROM tbl_collections;
'''):
if r[14] is not '':
permit, _ = ADFGPermit.objects.get_or_create(name=r[14])
else:
permit = None
col = Collection(project_id=r[0], id=r[1], study_location_id=r[2],
collection_type_id=r[3], collection_method_id=r[4],
number_of_traps=r[5], collection_start_date=r[17],
collection_start_time=r[18], collection_end_date=r[19],
collection_end_time=r[20], storage_location_id=r[10],
specimen_state=r[11], process_type_id=r[12], reagent_id=r[13],
adfg_permit=permit)
col.save()

View file

@ -215,22 +215,6 @@ class TblHashCollectionSpecies(models.Model):
unique_together = (('CollectionID', 'SpeciesID'),)
class TblHashCollectionTraps(models.Model):
colltrapid = models.AutoField(db_column='CollTrapID', primary_key=True) # Field name made lowercase.
collectionid = models.ForeignKey(TblCollections, db_column='CollectionID') # Field name made lowercase.
number_of_traps = models.IntegerField(db_column='Number_Of_Traps') # Field name made lowercase.
date_opened = models.DateField(db_column='Date_Opened') # Field name made lowercase.
time_opened = models.TimeField(db_column='Time_Opened') # Field name made lowercase.
date_closed = models.DateField(db_column='Date_Closed') # Field name made lowercase.
time_closed = models.TimeField(db_column='Time_Closed') # Field name made lowercase.
reference = models.CharField(db_column='Reference', max_length=255, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'tbl_HASH_Collection_Traps'
unique_together = (('CollectionID', 'Date_Opened', 'Time_Opened', 'Date_Closed', 'Time_Closed'),)
class TblHashPeopleSets(models.Model):
peoplesetid = models.AutoField(db_column='PeopleSetID', primary_key=True) # Field name made lowercase.
record_typeid = models.ForeignKey('TblLuRecordTypes', db_column='Record_TypeID') # Field name made lowercase.
@ -293,31 +277,6 @@ class TblLuBioMolecules(models.Model):
unique_together = (('BioMolecule', 'BioMolecule_Code'),)
class TblLuCollectionMethods(models.Model):
collection_methodid = models.AutoField(db_column='Collection_MethodID', primary_key=True) # Field name made lowercase.
collection_method = models.CharField(db_column='Collection_Method', max_length=100) # Field name made lowercase.
collection_method_code = models.CharField(db_column='Collection_Method_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
collection_method_class = models.CharField(db_column='Collection_Method_Class', max_length=50, 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_Collection_Methods'
unique_together = (('Collection_Method', 'Collection_Method_Code'),)
class TblLuCollectionTypes(models.Model):
collection_typeid = models.AutoField(db_column='Collection_TypeID', primary_key=True) # Field name made lowercase.
collection_type = models.CharField(db_column='Collection_Type', max_length=100) # Field name made lowercase.
collection_type_code = models.CharField(db_column='Collection_Type_Code', max_length=10, 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_Collection_Types'
unique_together = (('Collection_Type', 'Collection_Type_Code'),)
class TblLuCommentTypes(models.Model):
comment_typeid = models.AutoField(db_column='Comment_TypeID', primary_key=True) # Field name made lowercase.
comment_type = models.CharField(db_column='Comment_Type', max_length=100) # Field name made lowercase.