Location models
- region - site - municipal location - study location - storage location
This commit is contained in:
parent
31a9f87848
commit
3ee15528e8
8 changed files with 245 additions and 78 deletions
0
ccdb/locations/__init__.py
Normal file
0
ccdb/locations/__init__.py
Normal file
11
ccdb/locations/admin.py
Normal file
11
ccdb/locations/admin.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from .models import Region, Site, MunicipalLocation, \
|
||||
StudyLocation, StorageLocation
|
||||
|
||||
|
||||
admin.site.register(Region)
|
||||
admin.site.register(Site)
|
||||
admin.site.register(MunicipalLocation)
|
||||
admin.site.register(StudyLocation)
|
||||
admin.site.register(StorageLocation)
|
105
ccdb/locations/migrations/0001_initial.py
Normal file
105
ccdb/locations/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
# -*- 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='MunicipalLocation',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('code', models.CharField(max_length=10, blank=True)),
|
||||
('municipal_location_type', models.CharField(max_length=50, 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'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Region',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=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(populate_from='name', editable=False)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['sort_order'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Site',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('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)),
|
||||
('region', models.ForeignKey(to='locations.Region', null=True, blank=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['sort_order'],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='StorageLocation',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('facility', models.CharField(max_length=100)),
|
||||
('building', models.CharField(max_length=100)),
|
||||
('room', models.CharField(max_length=50, blank=True)),
|
||||
('freezer', models.CharField(max_length=50, blank=True)),
|
||||
('temp_c', models.IntegerField(null=True, 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='StudyLocation',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('code', models.CharField(max_length=10, blank=True)),
|
||||
('study_location_type', models.CharField(max_length=50, blank=True)),
|
||||
('treatment_type', models.CharField(max_length=100, blank=True)),
|
||||
('collecting_location', models.BooleanField(default=False)),
|
||||
('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)),
|
||||
('municipal_location', models.ForeignKey(to='locations.MunicipalLocation', null=True, blank=True)),
|
||||
('site', models.ForeignKey(to='locations.Site', null=True, blank=True)),
|
||||
],
|
||||
options={
|
||||
'ordering': ['sort_order'],
|
||||
},
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='region',
|
||||
unique_together=set([('name', 'code')]),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='municipallocation',
|
||||
name='site',
|
||||
field=models.ForeignKey(to='locations.Site'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='studylocation',
|
||||
unique_together=set([('site', 'name')]),
|
||||
),
|
||||
]
|
0
ccdb/locations/migrations/__init__.py
Normal file
0
ccdb/locations/migrations/__init__.py
Normal file
94
ccdb/locations/models.py
Normal file
94
ccdb/locations/models.py
Normal file
|
@ -0,0 +1,94 @@
|
|||
from django.db import models
|
||||
|
||||
from autoslug import AutoSlugField
|
||||
|
||||
|
||||
class Region(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 Site(models.Model):
|
||||
region = models.ForeignKey(Region, blank=True, null=True)
|
||||
name = models.CharField(max_length=100)
|
||||
code = models.CharField(max_length=10, 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:
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
class MunicipalLocation(models.Model):
|
||||
site = models.ForeignKey(Site)
|
||||
name = models.CharField(max_length=100)
|
||||
code = models.CharField(max_length=10, blank=True)
|
||||
municipal_location_type = models.CharField(max_length=50, 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:
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
class StudyLocation(models.Model):
|
||||
site = models.ForeignKey(Site, blank=True, null=True)
|
||||
name = models.CharField(max_length=100)
|
||||
code = models.CharField(max_length=10, blank=True)
|
||||
study_location_type = models.CharField(max_length=50, blank=True)
|
||||
treatment_type = models.CharField(max_length=100, blank=True)
|
||||
municipal_location = models.ForeignKey(MunicipalLocation,
|
||||
blank=True, null=True)
|
||||
collecting_location = models.BooleanField(default=False)
|
||||
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 = ('site', 'name')
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
class StorageLocation(models.Model):
|
||||
facility = models.CharField(max_length=100)
|
||||
building = models.CharField(max_length=100)
|
||||
room = models.CharField(max_length=50, blank=True)
|
||||
freezer = models.CharField(max_length=50, blank=True)
|
||||
temp_c = models.IntegerField(blank=True, null=True)
|
||||
description = models.CharField(max_length=255, blank=True)
|
||||
sort_order = models.IntegerField(blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
bldg = "".join(e[0].upper() for e in self.building.split())
|
||||
temp_c = '20'
|
||||
if self.temp_c:
|
||||
temp_c = self.temp_c
|
||||
|
||||
freezer = 'No Freezer'
|
||||
if self.freezer:
|
||||
freezer = self.freezer
|
||||
|
||||
return " ".join([bldg, str(temp_c)+'C', str(freezer)])
|
||||
|
||||
class Meta:
|
||||
ordering = ['sort_order']
|
|
@ -9,6 +9,8 @@ from ccdb.utils.data_import import setup_sqlite
|
|||
from ccdb.projects.models import Project, Grant, GrantReport
|
||||
from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \
|
||||
Material, Color
|
||||
from ccdb.locations.models import Region, Site, MunicipalLocation, \
|
||||
StudyLocation, StorageLocation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -104,3 +106,35 @@ def _import_data():
|
|||
color_id=r[4], material_id=r[5], volume=r[6],
|
||||
measurement_unit_id=r[7], sort_order=r[8])
|
||||
cl.save()
|
||||
|
||||
# Regions
|
||||
for r in c.execute('SELECT * FROM tbl_lu_regions;'):
|
||||
re = Region(id=r[0], name=r[1], code=r[2], sort_order=r[3])
|
||||
re.save()
|
||||
|
||||
# Site
|
||||
for r in c.execute('SELECT * FROM tbl_lu_sites;'):
|
||||
s = Site(region_id=r[0], id=r[1], name=r[2], code=r[3],
|
||||
description=r[4], sort_order=r[5])
|
||||
s.save()
|
||||
|
||||
# Municipal Locations
|
||||
for r in c.execute('SELECT * FROM tbl_lu_municipal_locations;'):
|
||||
ml = MunicipalLocation(site_id=r[0], id=r[1], name=r[2], code=r[3],
|
||||
municipal_location_type=r[4], description=r[5], sort_order=r[6])
|
||||
ml.save()
|
||||
|
||||
# Study Locations
|
||||
for r in c.execute('SELECT * FROM tbl_lu_study_locations;'):
|
||||
sl = StudyLocation(site_id=r[0], id=r[1], name=r[2], code=r[3],
|
||||
study_location_type=r[4], treatment_type=r[5],
|
||||
municipal_location_id=r[6], collecting_location=r[7],
|
||||
description=r[13], sort_order=r[14])
|
||||
sl.save()
|
||||
|
||||
# Storage Location
|
||||
for r in c.execute('SELECT * FROM tbl_lu_storage_locations;'):
|
||||
sl = StorageLocation(id=r[0], facility=r[1], building=r[2],
|
||||
room=r[3], freezer=r[4], temp_c=r[5],
|
||||
description=r[6], sort_order=r[7])
|
||||
sl.save()
|
||||
|
|
|
@ -41,6 +41,7 @@ LOCAL_APPS = (
|
|||
'ccdb.users', # custom users app
|
||||
'ccdb.projects',
|
||||
'ccdb.misc',
|
||||
'ccdb.locations',
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||
|
|
|
@ -370,20 +370,6 @@ class TblLuExperiments(models.Model):
|
|||
unique_together = (('Experiment_Name', 'Experiment_Code'),)
|
||||
|
||||
|
||||
class TblLuMunicipalLocations(models.Model):
|
||||
municipal_locationid = models.AutoField(db_column='Municipal_LocationID', primary_key=True) # Field name made lowercase.
|
||||
siteid = models.ForeignKey('TblLuSites', db_column='SiteID') # Field name made lowercase.
|
||||
municipal_location = models.CharField(db_column='Municipal_Location', max_length=100) # Field name made lowercase.
|
||||
municipal_location_code = models.CharField(db_column='Municipal_Location_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
|
||||
municipal_location_type = models.CharField(db_column='Municipal_Location_Type', max_length=50, blank=True, null=True) # Field name made lowercase.
|
||||
mlocation_short_description = models.CharField(db_column='MLocation_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_Municipal_Locations'
|
||||
|
||||
|
||||
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.
|
||||
|
@ -462,18 +448,6 @@ class TblLuRecordTypes(models.Model):
|
|||
db_table = 'tbl_LU_Record_Types'
|
||||
|
||||
|
||||
class TblLuRegions(models.Model):
|
||||
regionid = models.AutoField(db_column='RegionID', primary_key=True) # Field name made lowercase.
|
||||
region = models.CharField(db_column='Region', max_length=100) # Field name made lowercase.
|
||||
region_code = models.CharField(db_column='Region_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_Regions'
|
||||
unique_together = (('Region', 'Region_Code'),)
|
||||
|
||||
|
||||
class TblLuSampleTypes(models.Model):
|
||||
sample_typeid = models.AutoField(db_column='Sample_TypeID', primary_key=True) # Field name made lowercase.
|
||||
sample_type = models.CharField(db_column='Sample_Type', max_length=100) # Field name made lowercase.
|
||||
|
@ -487,19 +461,6 @@ class TblLuSampleTypes(models.Model):
|
|||
unique_together = (('Sample_Type', 'Sample_Type_Code'),)
|
||||
|
||||
|
||||
class TblLuSites(models.Model):
|
||||
regionid = models.ForeignKey(TblLuRegions, db_column='RegionID', blank=True, null=True) # Field name made lowercase.
|
||||
siteid = models.AutoField(db_column='SiteID', primary_key=True) # Field name made lowercase.
|
||||
site = models.CharField(db_column='Site', max_length=100) # Field name made lowercase.
|
||||
site_code = models.CharField(db_column='Site_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
|
||||
site_short_description = models.CharField(db_column='Site_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_Sites'
|
||||
|
||||
|
||||
class TblLuSpecies(models.Model):
|
||||
speciesid = models.AutoField(db_column='SpeciesID', primary_key=True) # Field name made lowercase.
|
||||
common_name = models.CharField(db_column='Common_Name', max_length=100) # Field name made lowercase.
|
||||
|
@ -514,45 +475,6 @@ class TblLuSpecies(models.Model):
|
|||
unique_together = (('Common_Name', 'Species'),)
|
||||
|
||||
|
||||
class TblLuStorageLocations(models.Model):
|
||||
storage_locationid = models.AutoField(db_column='Storage_LocationID', primary_key=True) # Field name made lowercase.
|
||||
facility = models.CharField(db_column='Facility', max_length=100) # Field name made lowercase.
|
||||
building = models.CharField(db_column='Building', max_length=100) # Field name made lowercase.
|
||||
room = models.CharField(db_column='Room', max_length=50, blank=True, null=True) # Field name made lowercase.
|
||||
freezer = models.CharField(db_column='Freezer', max_length=50, blank=True, null=True) # Field name made lowercase.
|
||||
temp_c = models.IntegerField(db_column='Temp_C', blank=True, null=True) # Field name made lowercase.
|
||||
slocation_short_description = models.CharField(db_column='SLocation_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.
|
||||
storage_location_code = models.CharField(db_column='Storage_Location_Code', unique=True, max_length=25) # Field name made lowercase.
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
db_table = 'tbl_LU_Storage_Locations'
|
||||
|
||||
|
||||
class TblLuStudyLocations(models.Model):
|
||||
siteid = models.ForeignKey(TblLuSites, db_column='SiteID', blank=True, null=True) # Field name made lowercase.
|
||||
study_locationid = models.AutoField(db_column='Study_LocationID', primary_key=True) # Field name made lowercase.
|
||||
study_location = models.CharField(db_column='Study_Location', max_length=100) # Field name made lowercase.
|
||||
study_location_code = models.CharField(db_column='Study_Location_Code', max_length=10, blank=True, null=True) # Field name made lowercase.
|
||||
study_location_type = models.CharField(db_column='Study_Location_Type', max_length=50, blank=True, null=True) # Field name made lowercase.
|
||||
treatment_type = models.CharField(db_column='Treatment_Type', max_length=100, blank=True, null=True) # Field name made lowercase.
|
||||
municipal_locationid = models.ForeignKey(TblLuMunicipalLocations, db_column='Municipal_LocationID', blank=True, null=True) # Field name made lowercase.
|
||||
collecting_location = models.BooleanField(db_column='Collecting_Location') # Field name made lowercase.
|
||||
latitude = models.FloatField(db_column='Latitude', blank=True, null=True) # Field name made lowercase.
|
||||
longitude = models.FloatField(db_column='Longitude', blank=True, null=True) # Field name made lowercase.
|
||||
utmx = models.FloatField(db_column='UTMx', blank=True, null=True) # Field name made lowercase.
|
||||
utmy = models.FloatField(db_column='UTMy', blank=True, null=True) # Field name made lowercase.
|
||||
datum = models.CharField(db_column='Datum', max_length=50, blank=True, null=True) # Field name made lowercase.
|
||||
slocation_short_description = models.CharField(db_column='SLocation_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_Study_Locations'
|
||||
unique_together = (('SiteID', 'Study_Location'),)
|
||||
|
||||
|
||||
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.
|
||||
|
|
Loading…
Add table
Reference in a new issue