Commit 654e02c6 authored by Luis García's avatar Luis García
Browse files

Add location to results

parent cf4b79cc
......@@ -61,6 +61,7 @@ INSTALLED_APPS = [
'corsheaders',
'ckeditor',
'ckeditor_uploader',
'django_cleanup.apps.CleanupConfig',
'status.apps.StatusConfig',
'core.apps.CoreConfig',
#'sc.apps.ScConfig',
......
from rest_framework.serializers import ModelSerializer, ValidationError
from api.utils import AsymetricRelatedField
from .models import Poll, Question, Response, Answer
from datetime import date
import json
from rest_framework.serializers import ModelSerializer, ValidationError, SerializerMethodField
from drf_extra_fields.geo_fields import PointField
from api.utils import AsymetricRelatedField
from project.serializers import ConsultationSerializer_temp
from datetime import date
from .models import Poll, Question, Response, Answer
class QuestionSerializer(ModelSerializer):
......@@ -47,8 +49,17 @@ class AnswerSerializer(ModelSerializer):
class ResponseSerializer(ModelSerializer):
answers = AnswerSerializer(many=True, read_only=True)
#location = location = PointField(source='owner.profile.location', )
location = SerializerMethodField(read_only=True)
class Meta:
model = Response
fields = ('id', 'poll', 'created', 'answers')
fields = ('id', 'poll', 'created', 'answers', 'location')
ref_name = 'Poll response'
def get_location(self, obj):
location = obj.owner.profile.location
response = None
if location:
response = json.loads(obj.owner.profile.location.geojson)
return response
\ No newline at end of file
......@@ -10,6 +10,7 @@ django-extensions==2.1.6
django-ckeditor==5.7.1
django-crontab==0.7.1
django-filter==2.1.0
django-cleanup==4.0.0
djangorestframework-jwt==1.11.0
djangorestframework-csv==2.1.0
social-auth-app-django==3.1.0
......
......@@ -225,10 +225,12 @@ class ResultsAnswersSerializer(ModelSerializer):
type = serializers.SerializerMethodField()
consultation = serializers.SerializerMethodField()
survey = serializers.SerializerMethodField()
location = serializers.SerializerMethodField()
location_wkt = serializers.SerializerMethodField()
class Meta:
model = Answer
fields = ('answer', 'question', 'type', 'consultation', 'survey', 'created')
fields = ('answer', 'question', 'type', 'consultation', 'survey', 'created', 'location', 'location_wkt')
def get_answer(self, obj):
response = obj.content['value']
......@@ -259,6 +261,20 @@ class ResultsAnswersSerializer(ModelSerializer):
def get_survey(self, obj):
return obj.response.survey.name
def get_location(self, obj):
location = obj.response.owner.profile.location
response = None
if location:
response = json.loads(obj.response.owner.profile.location.geojson)
return response
def get_location_wkt(self, obj):
location = obj.response.owner.profile.location
response = None
if location:
response = obj.response.owner.profile.location.wkt
return response
class ResultsInputsSerializer(Serializer):
name = serializers.CharField(max_length=100)
description = serializers.CharField(max_length=300)
......
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