Fix CaseStudy serialisation..

..by ensuring CS images are serialised correctly
This commit is contained in:
Carl van Tonder 2018-05-30 14:21:48 -04:00
parent 2bb7ea5561
commit c32ddf1abb
2 changed files with 13 additions and 3 deletions

View File

@ -145,7 +145,7 @@ function getLabelClass(pos_or_neg) {
function popup(feature, layer) { function popup(feature, layer) {
layer.bindPopup( layer.bindPopup(
"<img src='"+feature.properties.image+"' width='100%'>"+ "<img src='"+feature.properties.images[0].file+"' width='100%'>"+
"<div class='popup-head'>"+ "<div class='popup-head'>"+
"<h5>"+feature.properties.entry_name+"</h5>" + "<h5>"+feature.properties.entry_name+"</h5>" +
"<i>"+feature.properties.country_name+"</i>"+ "<i>"+feature.properties.country_name+"</i>"+

View File

@ -18,10 +18,13 @@ from django.urls import reverse
from django.conf.urls.i18n import i18n_patterns from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from apps.map.models import CaseStudy
from rest_framework import routers, serializers, viewsets from rest_framework import routers, serializers, viewsets
from rest_framework_gis import serializers as gis_serializers from rest_framework_gis import serializers as gis_serializers
from apps.files.models import File
from apps.map.models import CaseStudy
from .views import LanguageDropdownView from .views import LanguageDropdownView
class UserSerializer(serializers.HyperlinkedModelSerializer): class UserSerializer(serializers.HyperlinkedModelSerializer):
@ -35,10 +38,17 @@ class UserViewSet(viewsets.ModelViewSet):
serializer_class = UserSerializer serializer_class = UserSerializer
class FileSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = File
fields = ('file',)
class CaseStudySerializer(gis_serializers.GeoFeatureModelSerializer): class CaseStudySerializer(gis_serializers.GeoFeatureModelSerializer):
sector_of_economy = serializers.CharField(source='get_sector_of_economy_display') sector_of_economy = serializers.CharField(source='get_sector_of_economy_display')
country_name = serializers.CharField(source='get_country_display') country_name = serializers.CharField(source='get_country_display')
positive_or_negative_display = serializers.CharField(source='get_positive_or_negative_display') positive_or_negative_display = serializers.CharField(source='get_positive_or_negative_display')
images = FileSerializer(many=True)
class Meta: class Meta:
model = CaseStudy model = CaseStudy
@ -47,7 +57,7 @@ class CaseStudySerializer(gis_serializers.GeoFeatureModelSerializer):
'country', 'country',
'country_name', 'country_name',
'entry_name', 'entry_name',
'image', 'images',
'location', 'location',
'positive_or_negative', 'positive_or_negative',
'positive_or_negative_display', 'positive_or_negative_display',