Commit 932c3d36 authored by Luis García's avatar Luis García
Browse files

Update the api results inputs

parent 31e0b25b
......@@ -7,6 +7,7 @@ from rest_framework.response import Response as Http_Response
from rest_framework.viewsets import ModelViewSet, GenericViewSet
from rest_framework import mixins
#csv
from itertools import chain
from rest_framework.settings import api_settings
from rest_framework_csv import renderers as r
......@@ -229,15 +230,33 @@ class ResultsInputsViewSet(mixins.ListModelMixin, GenericViewSet):
renderer_classes = (r.CSVRenderer, ) + tuple(api_settings.DEFAULT_RENDERER_CLASSES)
def get_queryset(self):
spatial_inputs = SpatialInput.objects.filter(visible=True).annotate(
#Get the socialinputs and get only the visibles
spatial_inputs = SpatialInput.objects.filter(
visible=True
).values(
'name', 'description', 'geometry', 'photo'
#Add the extra fields
).annotate(
category=F('category__name'),
origin=Value('platform', CharField()),
survey=F('answer__response__survey__name'),
consultation=F('answer__response__survey__consultation__name')
).values('name', 'description', 'category', 'geometry', 'origin', 'photo', 'survey', 'consultation')
social_inputs = SocialInput.objects.filter(visible=True).annotate(
).values(
'name', 'description', 'category', 'geometry', 'origin', 'photo', 'survey', 'consultation'
)
#Get the social inputs
social_inputs = SocialInput.objects.filter(
visible=True
).values(
'description', 'geometry', 'photo'
).annotate(
name=F('description'),
category=Value('', CharField()),
origin=F('network'),
consultation=F('survey__consultation__name')
).values('name', 'description', 'category', 'geometry', 'origin', 'photo', 'survey', 'consultation')
return spatial_inputs#.union(social_inputs)
\ No newline at end of file
consultation=F('survey__consultation__name'),
survey=F('survey__name'),
).values(
'name', 'description', 'category', 'geometry', 'origin', 'photo', 'survey', 'consultation'
)
#join the querysets and return it
return list(chain(spatial_inputs, social_inputs))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment