diff --git a/ccdb/api/urls.py b/ccdb/api/urls.py index 866fc40..859e432 100644 --- a/ccdb/api/urls.py +++ b/ccdb/api/urls.py @@ -23,6 +23,8 @@ router.register(r'collection-types', router.register(r'collection-flaws', collections_viewsets.FlawViewSet) router.register(r'adfg-permits', collections_viewsets.ADFGPermitViewSet) +router.register(r'datasheet-attachments', + collections_viewsets.DatasheetAttachmentViewSet) # Projects router.register(r'projects', projects_viewsets.ProjectViewSet) # Locations diff --git a/ccdb/collections_ccdb/serializers.py b/ccdb/collections_ccdb/serializers.py index c3e63f9..de65a02 100644 --- a/ccdb/collections_ccdb/serializers.py +++ b/ccdb/collections_ccdb/serializers.py @@ -1,7 +1,7 @@ from rest_framework_json_api import serializers from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType, - Flaw) + Flaw, DatasheetAttachment) class CollectionSerializer(serializers.ModelSerializer): @@ -18,6 +18,8 @@ class CollectionSerializer(serializers.ModelSerializer): 'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer', 'collection_species': 'ccdb.species.serializers.CollectionSpeciesSerializer', + 'datasheets': + 'ccdb.collections_ccdb.serializers.DatasheetAttachmentSerializer', } class Meta: @@ -28,8 +30,8 @@ class CollectionSerializer(serializers.ModelSerializer): 'collection_end_date', 'collection_end_time', 'storage_location', 'specimen_state', 'process_type', 'reagent', 'adfg_permit', 'flaw', 'display_name', - 'collection_species') - read_only_fields = ('collection_species',) + 'collection_species', 'datasheets') + read_only_fields = ('collection_species', 'datasheets') class ADFGPermitSerializer(serializers.ModelSerializer): @@ -55,3 +57,13 @@ class FlawSerializer(serializers.ModelSerializer): class Meta: model = Flaw 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') diff --git a/ccdb/collections_ccdb/viewsets.py b/ccdb/collections_ccdb/viewsets.py index 9e74c0b..1508fe0 100644 --- a/ccdb/collections_ccdb/viewsets.py +++ b/ccdb/collections_ccdb/viewsets.py @@ -3,10 +3,10 @@ from django_filters import rest_framework as filters from .filters import CollectionFilter from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType, - Flaw) + Flaw, DatasheetAttachment) from .serializers import (CollectionSerializer, CollectionMethodSerializer, CollectionTypeSerializer, FlawSerializer, - ADFGPermitSerializer) + ADFGPermitSerializer, DatasheetAttachmentSerializer) class CollectionViewSet(viewsets.ModelViewSet): @@ -34,3 +34,8 @@ class FlawViewSet(viewsets.ModelViewSet): class ADFGPermitViewSet(viewsets.ModelViewSet): queryset = ADFGPermit.objects.all() serializer_class = ADFGPermitSerializer + + +class DatasheetAttachmentViewSet(viewsets.ModelViewSet): + queryset = DatasheetAttachment.objects.all() + serializer_class = DatasheetAttachmentSerializer