ENH: Collection attachments (#36)

This commit is contained in:
Matthew Ryan Dillon 2017-12-01 12:57:05 -07:00 committed by GitHub
parent 2a7b11720e
commit a908b06b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View file

@ -23,6 +23,8 @@ router.register(r'collection-types',
router.register(r'collection-flaws', router.register(r'collection-flaws',
collections_viewsets.FlawViewSet) collections_viewsets.FlawViewSet)
router.register(r'adfg-permits', collections_viewsets.ADFGPermitViewSet) router.register(r'adfg-permits', collections_viewsets.ADFGPermitViewSet)
router.register(r'datasheet-attachments',
collections_viewsets.DatasheetAttachmentViewSet)
# Projects # Projects
router.register(r'projects', projects_viewsets.ProjectViewSet) router.register(r'projects', projects_viewsets.ProjectViewSet)
# Locations # Locations

View file

@ -1,7 +1,7 @@
from rest_framework_json_api import serializers from rest_framework_json_api import serializers
from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType, from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType,
Flaw) Flaw, DatasheetAttachment)
class CollectionSerializer(serializers.ModelSerializer): class CollectionSerializer(serializers.ModelSerializer):
@ -18,6 +18,8 @@ class CollectionSerializer(serializers.ModelSerializer):
'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer', 'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
'collection_species': 'collection_species':
'ccdb.species.serializers.CollectionSpeciesSerializer', 'ccdb.species.serializers.CollectionSpeciesSerializer',
'datasheets':
'ccdb.collections_ccdb.serializers.DatasheetAttachmentSerializer',
} }
class Meta: class Meta:
@ -28,8 +30,8 @@ class CollectionSerializer(serializers.ModelSerializer):
'collection_end_date', 'collection_end_time', 'collection_end_date', 'collection_end_time',
'storage_location', 'specimen_state', 'process_type', 'storage_location', 'specimen_state', 'process_type',
'reagent', 'adfg_permit', 'flaw', 'display_name', 'reagent', 'adfg_permit', 'flaw', 'display_name',
'collection_species') 'collection_species', 'datasheets')
read_only_fields = ('collection_species',) read_only_fields = ('collection_species', 'datasheets')
class ADFGPermitSerializer(serializers.ModelSerializer): class ADFGPermitSerializer(serializers.ModelSerializer):
@ -55,3 +57,13 @@ class FlawSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Flaw model = Flaw
fields = ('id', 'name', 'description', 'sort_order') fields = ('id', 'name', 'description', 'sort_order')
class DatasheetAttachmentSerializer(serializers.ModelSerializer):
included_serializers = {
'collection': 'ccdb.collections_ccdb.serializers.CollectionSerializer',
}
class Meta:
model = DatasheetAttachment
fields = ('id', 'collection', 'datasheet')

View file

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