ENH: Expose species (#32)
This commit is contained in:
parent
6c5ddbec1e
commit
92a349c496
5 changed files with 52 additions and 2 deletions
|
@ -7,6 +7,7 @@ from ..utils import viewsets as utils_viewsets
|
||||||
from ..collections_ccdb import viewsets as collections_viewsets
|
from ..collections_ccdb import viewsets as collections_viewsets
|
||||||
from ..projects import viewsets as projects_viewsets
|
from ..projects import viewsets as projects_viewsets
|
||||||
from ..locations import viewsets as locations_viewsets
|
from ..locations import viewsets as locations_viewsets
|
||||||
|
from ..species import viewsets as species_viewsets
|
||||||
|
|
||||||
|
|
||||||
router = routers.DefaultRouter(trailing_slash=False)
|
router = routers.DefaultRouter(trailing_slash=False)
|
||||||
|
@ -28,6 +29,10 @@ router.register(r'projects', projects_viewsets.ProjectViewSet)
|
||||||
router.register(r'regions', locations_viewsets.RegionViewSet)
|
router.register(r'regions', locations_viewsets.RegionViewSet)
|
||||||
router.register(r'sites', locations_viewsets.SiteViewSet)
|
router.register(r'sites', locations_viewsets.SiteViewSet)
|
||||||
router.register(r'study-locations', locations_viewsets.StudyLocationViewSet)
|
router.register(r'study-locations', locations_viewsets.StudyLocationViewSet)
|
||||||
|
# Species
|
||||||
|
router.register(r'species', species_viewsets.SpeciesViewSet)
|
||||||
|
router.register(r'collection-species',
|
||||||
|
species_viewsets.CollectionSpeciesViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^auth/login/', api_v.Login.as_view()),
|
url(r'^auth/login/', api_v.Login.as_view()),
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django_filters import rest_framework as filters
|
||||||
from .models import Collection, CollectionMethod, ADFGPermit
|
from .models import Collection, CollectionMethod, ADFGPermit
|
||||||
from ccdb.projects.models import Project
|
from ccdb.projects.models import Project
|
||||||
from ccdb.locations.models import Region, Site, StudyLocation
|
from ccdb.locations.models import Region, Site, StudyLocation
|
||||||
|
from ccdb.species.models import Species
|
||||||
|
|
||||||
|
|
||||||
class CollectionFilter(filters.FilterSet):
|
class CollectionFilter(filters.FilterSet):
|
||||||
|
@ -43,9 +44,15 @@ class CollectionFilter(filters.FilterSet):
|
||||||
queryset=ADFGPermit.objects.all(),
|
queryset=ADFGPermit.objects.all(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
species = ModelMultipleChoiceFilter(
|
||||||
|
name='collection_species__species__id',
|
||||||
|
to_field_name='id',
|
||||||
|
queryset=Species.objects.all(),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Collection
|
model = Collection
|
||||||
fields = ['project', 'region', 'site', 'study_location',
|
fields = ['project', 'region', 'site', 'study_location',
|
||||||
'collection_method', 'number_of_traps',
|
'collection_method', 'number_of_traps',
|
||||||
'collection_start_date', 'collection_end_date',
|
'collection_start_date', 'collection_end_date',
|
||||||
'adfg_permit']
|
'adfg_permit', 'species']
|
||||||
|
|
|
@ -16,6 +16,8 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||||
'collection_type':
|
'collection_type':
|
||||||
'ccdb.collections_ccdb.serializers.CollectionTypeSerializer',
|
'ccdb.collections_ccdb.serializers.CollectionTypeSerializer',
|
||||||
'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
|
'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
|
||||||
|
'collection_species':
|
||||||
|
'ccdb.species.serializers.CollectionSpeciesSerializer',
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -25,7 +27,8 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||||
'collection_start_date', 'collection_start_time',
|
'collection_start_date', 'collection_start_time',
|
||||||
'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')
|
||||||
|
|
||||||
|
|
||||||
class ADFGPermitSerializer(serializers.ModelSerializer):
|
class ADFGPermitSerializer(serializers.ModelSerializer):
|
||||||
|
|
21
ccdb/species/serializers.py
Normal file
21
ccdb/species/serializers.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from rest_framework_json_api import serializers
|
||||||
|
|
||||||
|
from .models import Species, CollectionSpecies
|
||||||
|
|
||||||
|
|
||||||
|
class SpeciesSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Species
|
||||||
|
fields = ('common_name', 'genus', 'species', 'parasite', 'sort_order')
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionSpeciesSerializer(serializers.ModelSerializer):
|
||||||
|
included_serializers = {
|
||||||
|
'collection': 'ccdb.collections_ccdb.serializers.CollectionSerializer',
|
||||||
|
'species': 'ccdb.species.serializers.SpeciesSerializer',
|
||||||
|
}
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CollectionSpecies
|
||||||
|
fields = ('id', 'sex', 'count', 'count_estimated', 'collection',
|
||||||
|
'species')
|
14
ccdb/species/viewsets.py
Normal file
14
ccdb/species/viewsets.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from rest_framework import viewsets
|
||||||
|
|
||||||
|
from .models import Species, CollectionSpecies
|
||||||
|
from .serializers import SpeciesSerializer, CollectionSpeciesSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class SpeciesViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = Species.objects.all()
|
||||||
|
serializer_class = SpeciesSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionSpeciesViewSet(viewsets.ModelViewSet):
|
||||||
|
queryset = CollectionSpecies.objects.all()
|
||||||
|
serializer_class = CollectionSpeciesSerializer
|
Loading…
Add table
Reference in a new issue