ENH: Collections IACUC and ADFG (#31)

This commit is contained in:
Matthew Ryan Dillon 2017-11-14 08:26:48 -07:00 committed by GitHub
parent b8e7bb9bcc
commit 6c5ddbec1e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 5 deletions

View file

@ -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

View file

@ -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']

View file

@ -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')

View file

@ -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

View file

@ -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