ENH: Collection environmental measurements (#44)

This commit is contained in:
Matthew Ryan Dillon 2018-01-14 16:57:52 -07:00 committed by GitHub
parent 8d356716b4
commit 45da820a0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 7 deletions

View file

@ -22,6 +22,8 @@ router.register(r'collection-types',
collections_viewsets.CollectionTypeViewSet)
router.register(r'collection-flaws',
collections_viewsets.FlawViewSet)
router.register(r'collection-measurements',
collections_viewsets.CollectionMeasurementViewSet)
router.register(r'adfg-permits', collections_viewsets.ADFGPermitViewSet)
router.register(r'datasheet-attachments',
collections_viewsets.DatasheetAttachmentViewSet)

View file

@ -1,7 +1,8 @@
from django.contrib import admin
from .models import (CollectionType, CollectionMethod, Flaw, ADFGPermit,
DatasheetAttachment, CollectionTrap, Collection)
DatasheetAttachment, CollectionTrap, Collection,
CollectionMeasurement)
from ..species.models import CollectionSpecies
@ -57,8 +58,12 @@ class CollectionSpeciesInlineAdmin(admin.TabularInline):
model = CollectionSpecies
class CollectionMeasurementInlineAdmin(admin.TabularInline):
model = CollectionMeasurement
class CollectionAdmin(admin.ModelAdmin):
inlines = (CollectionSpeciesInlineAdmin, )
inlines = (CollectionSpeciesInlineAdmin, CollectionMeasurementInlineAdmin)
list_display = ('project', 'study_location', 'collection_end_date',
'collection_type', 'collection_method')
list_display_links = ('project', 'study_location', 'collection_end_date',

View file

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2018-01-04 13:57
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('collections_ccdb', '0006_collection_notes'),
]
operations = [
migrations.CreateModel(
name='CollectionMeasurement',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_measured', models.DateField()),
('time_measured', models.TimeField()),
('water_temp_c', models.FloatField(null=True)),
('air_temp_c', models.FloatField(null=True)),
('collection', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='env_measurements', to='collections_ccdb.Collection')),
],
options={
'ordering': ['date_measured', 'time_measured'],
},
),
migrations.AlterUniqueTogether(
name='collectionmeasurement',
unique_together=set([('collection', 'date_measured', 'time_measured')]),
),
]

View file

@ -123,3 +123,15 @@ class CollectionTrap(models.Model):
class Meta:
unique_together = ('collection', 'date_opened', 'time_opened',
'date_closed', 'time_closed')
class CollectionMeasurement(models.Model):
collection = models.ForeignKey(Collection, related_name='env_measurements')
date_measured = models.DateField()
time_measured = models.TimeField()
water_temp_c = models.FloatField(null=True)
air_temp_c = models.FloatField(null=True)
class Meta:
unique_together = ('collection', 'date_measured', 'time_measured')
ordering = ['date_measured', 'time_measured']

View file

@ -1,7 +1,7 @@
from rest_framework_json_api import serializers
from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType,
Flaw, DatasheetAttachment)
Flaw, DatasheetAttachment, CollectionMeasurement)
class CollectionSerializer(serializers.ModelSerializer):
@ -20,6 +20,9 @@ class CollectionSerializer(serializers.ModelSerializer):
'ccdb.species.serializers.CollectionSpeciesSerializer',
'datasheets':
'ccdb.collections_ccdb.serializers.DatasheetAttachmentSerializer',
'env_measurements':
'ccdb.collections_ccdb.serializers.'
'CollectionMeasurementSerializer',
}
class Meta:
@ -30,8 +33,10 @@ class CollectionSerializer(serializers.ModelSerializer):
'collection_end_date', 'collection_end_time',
'storage_location', 'specimen_state', 'process_type',
'reagent', 'adfg_permit', 'collection_flaw', 'display_name',
'collection_species', 'datasheets', 'notes')
read_only_fields = ('collection_species', 'datasheets')
'collection_species', 'datasheets', 'notes',
'env_measurements')
read_only_fields = ('collection_species', 'datasheets',
'env_measurements')
class ADFGPermitSerializer(serializers.ModelSerializer):
@ -67,3 +72,14 @@ class DatasheetAttachmentSerializer(serializers.ModelSerializer):
class Meta:
model = DatasheetAttachment
fields = ('id', 'collection', 'datasheet')
class CollectionMeasurementSerializer(serializers.ModelSerializer):
included_serializers = {
'collection': 'ccdb.collections_ccdb.serializers.CollectionSerializer',
}
class Meta:
model = CollectionMeasurement
fields = ('id', 'collection', 'date_measured', 'time_measured',
'water_temp_c', 'air_temp_c')

View file

@ -3,10 +3,11 @@ from django_filters import rest_framework as filters
from .filters import CollectionFilter
from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType,
Flaw, DatasheetAttachment)
Flaw, DatasheetAttachment, CollectionMeasurement)
from .serializers import (CollectionSerializer, CollectionMethodSerializer,
CollectionTypeSerializer, FlawSerializer,
ADFGPermitSerializer, DatasheetAttachmentSerializer)
ADFGPermitSerializer, DatasheetAttachmentSerializer,
CollectionMeasurementSerializer)
class CollectionViewSet(viewsets.ModelViewSet):
@ -39,3 +40,8 @@ class ADFGPermitViewSet(viewsets.ModelViewSet):
class DatasheetAttachmentViewSet(viewsets.ModelViewSet):
queryset = DatasheetAttachment.objects.all()
serializer_class = DatasheetAttachmentSerializer
class CollectionMeasurementViewSet(viewsets.ModelViewSet):
queryset = CollectionMeasurement.objects.all()
serializer_class = CollectionMeasurementSerializer