Trap species and collection species

This commit is contained in:
Matthew Ryan Dillon 2016-02-01 13:31:32 -07:00
parent 040fe41285
commit 80e96ec81b
6 changed files with 121 additions and 28 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Species
from .models import Species, TrapSpecies, CollectionSpecies
class SpeciesAdmin(admin.ModelAdmin):
@ -11,4 +11,22 @@ class SpeciesAdmin(admin.ModelAdmin):
fields = ('common_name', 'genus', 'species', 'parasite', 'sort_order')
class TrapSpeciesAdmin(admin.ModelAdmin):
list_display = ('collection_trap', 'species', 'sex', 'count', 'count_estimated')
list_display_links = ('count',)
search_fields = ('collection_trap', 'species', 'sex', 'count', 'count_estimated')
list_per_page = 25
fields = ('collection_trap', 'species', 'sex', 'count', 'count_estimated')
class CollectionSpeciesAdmin(admin.ModelAdmin):
list_display = ('collection', 'species', 'sex', 'count', 'count_estimated')
list_display_links = ('count',)
search_fields = ('collection', 'species', 'sex', 'count', 'count_estimated')
list_per_page = 25
fields = ('collection', 'species', 'sex', 'count', 'count_estimated')
admin.site.register(Species, SpeciesAdmin)
admin.site.register(TrapSpecies, TrapSpeciesAdmin)
admin.site.register(CollectionSpecies, CollectionSpeciesAdmin)

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('collections_ccdb', '0001_initial'),
('species', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='TrapSpecies',
fields=[
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
('sex', models.CharField(blank=True, max_length=25)),
('count', models.IntegerField(blank=True, null=True)),
('count_estimated', models.BooleanField(default=False)),
('collection_trap', models.ForeignKey(to='collections_ccdb.CollectionTrap')),
('species', models.ForeignKey(to='species.Species')),
],
options={
'verbose_name_plural': 'trap-species',
},
),
]

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('collections_ccdb', '0001_initial'),
('species', '0002_trapspecies'),
]
operations = [
migrations.CreateModel(
name='CollectionSpecies',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('sex', models.CharField(blank=True, max_length=25)),
('count', models.IntegerField(null=True, blank=True)),
('count_estimated', models.BooleanField(default=False)),
('collection', models.ForeignKey(to='collections_ccdb.Collection')),
('species', models.ForeignKey(to='species.Species')),
],
options={
'verbose_name_plural': 'collection-species',
},
),
migrations.AlterUniqueTogether(
name='collectionspecies',
unique_together=set([('collection', 'species')]),
),
]

View file

@ -18,3 +18,32 @@ class Species(models.Model):
unique_together = ('common_name', 'species')
ordering = ['sort_order']
verbose_name_plural = 'species'
class TrapSpecies(models.Model):
collection_trap = models.ForeignKey('collections_ccdb.CollectionTrap')
species = models.ForeignKey(Species)
sex = models.CharField(max_length=25, blank=True)
count = models.IntegerField(blank=True, null=True)
count_estimated = models.BooleanField(default=False)
def __str__(self):
return "{} {}".format(self.collection_trap, self.species)
class Meta:
verbose_name_plural = 'trap-species'
class CollectionSpecies(models.Model):
collection = models.ForeignKey('collections_ccdb.Collection')
species = models.ForeignKey(Species)
sex = models.CharField(max_length=25, blank=True)
count = models.IntegerField(blank=True, null=True)
count_estimated = models.BooleanField(default=False)
def __str__(self):
return "{} {}".format(self.collection, self.species)
class Meta:
unique_together = ('collection', 'species')
verbose_name_plural = 'collection-species'

View file

@ -12,7 +12,7 @@ from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \
Material, Color
from ccdb.locations.models import Region, Site, MunicipalLocation, \
StudyLocation, StorageLocation
from ccdb.species.models import Species
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
@ -206,3 +206,13 @@ def _import_admin_data():
specimen_state=r[11], process_type_id=r[12], reagent_id=r[13],
adfg_permit=permit)
col.save()
# Collection Species
for r in c.execute('SELECT * FROM tbl_hash_collection_species;'):
# No PK field in Andre's file
cs = CollectionSpecies(collection_id=r[0], species_id=r[1],
sex=r[2], count=r[3], count_estimated=r[4])
try:
cs.save()
except IntegrityError:
pass

View file

@ -202,19 +202,6 @@ class TblHashCollectionExperiments(models.Model):
unique_together = (('CollectionID', 'ExperimentID'),)
class TblHashCollectionSpecies(models.Model):
collectionid = models.ForeignKey(TblCollections, db_column='CollectionID') # Field name made lowercase.
speciesid = models.ForeignKey('TblLuSpecies', db_column='SpeciesID') # Field name made lowercase.
sex = models.CharField(db_column='Sex', max_length=25, blank=True, null=True) # Field name made lowercase.
count = models.IntegerField(db_column='Count', blank=True, null=True) # Field name made lowercase.
count_estimated = models.BooleanField(db_column='Count_Estimated') # Field name made lowercase.
class Meta:
managed = False
db_table = 'tbl_HASH_Collection_Species'
unique_together = (('CollectionID', 'SpeciesID'),)
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.
@ -226,19 +213,6 @@ class TblHashPeopleSets(models.Model):
db_table = 'tbl_HASH_People_Sets'
class TblHashTrapSpecies(models.Model):
trapspeciesid = models.AutoField(db_column='TrapSpeciesID', primary_key=True) # Field name made lowercase.
colltrapid = models.ForeignKey(TblHashCollectionTraps, db_column='CollTrapID') # Field name made lowercase.
speciesid = models.ForeignKey('TblLuSpecies', db_column='SpeciesID') # Field name made lowercase.
sex = models.CharField(db_column='Sex', max_length=25, blank=True, null=True) # Field name made lowercase.
count = models.IntegerField(db_column='Count', blank=True, null=True) # Field name made lowercase.
count_estimated = models.BooleanField(db_column='Count_Estimated') # Field name made lowercase.
class Meta:
managed = False
db_table = 'tbl_HASH_Trap_Species'
class TblLuAffiliations(models.Model):
affiliationid = models.AutoField(db_column='AffiliationID', primary_key=True) # Field name made lowercase.
affiliation = models.CharField(db_column='Affiliation', max_length=100) # Field name made lowercase.