diff --git a/ccdb/api/urls.py b/ccdb/api/urls.py index 7aab9ca..f841f7a 100644 --- a/ccdb/api/urls.py +++ b/ccdb/api/urls.py @@ -21,6 +21,7 @@ router.register(r'collection-types', collections_viewsets.CollectionTypeViewSet) router.register(r'collection-flaws', collections_viewsets.FlawViewSet) +router.register(r'adfg-permits', collections_viewsets.ADFGPermitViewSet) # Projects router.register(r'projects', projects_viewsets.ProjectViewSet) # Locations diff --git a/ccdb/collections_ccdb/filters.py b/ccdb/collections_ccdb/filters.py index e031b69..fba756b 100644 --- a/ccdb/collections_ccdb/filters.py +++ b/ccdb/collections_ccdb/filters.py @@ -1,7 +1,7 @@ from django_filters.filters import ModelMultipleChoiceFilter from django_filters import rest_framework as filters -from .models import Collection, CollectionMethod +from .models import Collection, CollectionMethod, ADFGPermit from ccdb.projects.models import Project from ccdb.locations.models import Region, Site, StudyLocation @@ -37,8 +37,15 @@ class CollectionFilter(filters.FilterSet): queryset=CollectionMethod.objects.all(), ) + adfg_permit = ModelMultipleChoiceFilter( + name='adfg_permit__id', + to_field_name='id', + queryset=ADFGPermit.objects.all(), + ) + class Meta: model = Collection fields = ['project', 'region', 'site', 'study_location', 'collection_method', 'number_of_traps', - 'collection_start_date', 'collection_end_date'] + 'collection_start_date', 'collection_end_date', + 'adfg_permit'] diff --git a/ccdb/collections_ccdb/models.py b/ccdb/collections_ccdb/models.py index 2550e33..d1b3da5 100644 --- a/ccdb/collections_ccdb/models.py +++ b/ccdb/collections_ccdb/models.py @@ -51,6 +51,9 @@ class ADFGPermit(models.Model): ordering = ['sort_order'] verbose_name = 'ADFG Permit' + class JSONAPIMeta: + resource_name = 'AdfgPermit' + class Collection(models.Model): project = models.ForeignKey('projects.Project', related_name='collections') diff --git a/ccdb/collections_ccdb/serializers.py b/ccdb/collections_ccdb/serializers.py index 5f3ccc4..7f243c0 100644 --- a/ccdb/collections_ccdb/serializers.py +++ b/ccdb/collections_ccdb/serializers.py @@ -1,10 +1,13 @@ from rest_framework_json_api import serializers -from .models import Collection, CollectionMethod, CollectionType, Flaw +from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType, + Flaw) class CollectionSerializer(serializers.ModelSerializer): included_serializers = { + 'adfg_permit': + 'ccdb.collections_ccdb.serializers.ADFGPermitSerializer', 'project': 'ccdb.projects.serializers.ProjectSerializer', 'site': 'ccdb.locations.serializers.SiteSerializer', 'study_location': 'ccdb.locations.serializers.StudyLocationSerializer', @@ -25,6 +28,12 @@ class CollectionSerializer(serializers.ModelSerializer): 'reagent', 'adfg_permit', 'flaw', 'display_name') +class ADFGPermitSerializer(serializers.ModelSerializer): + class Meta: + model = ADFGPermit + fields = ('id', 'name', 'sort_order') + + class CollectionMethodSerializer(serializers.ModelSerializer): class Meta: model = CollectionMethod diff --git a/ccdb/collections_ccdb/viewsets.py b/ccdb/collections_ccdb/viewsets.py index 1581e6c..9e74c0b 100644 --- a/ccdb/collections_ccdb/viewsets.py +++ b/ccdb/collections_ccdb/viewsets.py @@ -2,9 +2,11 @@ from rest_framework import viewsets from django_filters import rest_framework as filters from .filters import CollectionFilter -from .models import Collection, CollectionMethod, CollectionType, Flaw +from .models import (ADFGPermit, Collection, CollectionMethod, CollectionType, + Flaw) from .serializers import (CollectionSerializer, CollectionMethodSerializer, - CollectionTypeSerializer, FlawSerializer) + CollectionTypeSerializer, FlawSerializer, + ADFGPermitSerializer) class CollectionViewSet(viewsets.ModelViewSet): @@ -27,3 +29,8 @@ class CollectionTypeViewSet(viewsets.ModelViewSet): class FlawViewSet(viewsets.ModelViewSet): queryset = Flaw.objects.all() serializer_class = FlawSerializer + + +class ADFGPermitViewSet(viewsets.ModelViewSet): + queryset = ADFGPermit.objects.all() + serializer_class = ADFGPermitSerializer