113 lines
3.4 KiB
Python
113 lines
3.4 KiB
Python
from rest_framework import serializers
|
|
from right_tree.api.models import *
|
|
|
|
|
|
class ToleranceLevelSerializer(serializers.HyperlinkedModelSerializer):
|
|
class Meta:
|
|
model = ToleranceLevel
|
|
fields = ['level']
|
|
|
|
|
|
class EcologicalRegionSerializer(serializers.HyperlinkedModelSerializer):
|
|
class Meta:
|
|
model = EcologicalRegion
|
|
fields = ['name']
|
|
|
|
|
|
class EcologicalDistrictLayerSerializer(serializers.HyperlinkedModelSerializer):
|
|
ecological_district = serializers.CharField(
|
|
max_length=50, source='ecologic_1')
|
|
ecological_region = serializers.CharField(
|
|
max_length=50, source='ecologic_2')
|
|
|
|
class Meta:
|
|
model = EcologicalDistrictLayer
|
|
fields = ['ecological_district', 'ecological_region']
|
|
|
|
|
|
class SoilOrderSerializer(serializers.HyperlinkedModelSerializer):
|
|
soil_name = serializers.CharField(max_length=50, source='name')
|
|
soil_code = serializers.CharField(max_length=1, source='code')
|
|
|
|
class Meta:
|
|
model = SoilOrder
|
|
fields = ['soil_name', 'soil_code']
|
|
|
|
|
|
class SoilVariantSerializer(serializers.HyperlinkedModelSerializer):
|
|
class Meta:
|
|
model = SoilVariant
|
|
fields = ['name']
|
|
|
|
|
|
class SimpleHabitatImageSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
|
|
class Meta:
|
|
model = HabitatImage
|
|
fields = ['id', 'name', 'image_filename']
|
|
|
|
|
|
class ZoneSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
redirect_habitat = SimpleHabitatImageSerializer()
|
|
|
|
class Meta:
|
|
model = Zone
|
|
fields = ['id', 'name', 'variant',
|
|
'refined_variant', 'redirect_habitat']
|
|
|
|
|
|
class ZoneImageSegmentSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
zone = ZoneSerializer()
|
|
|
|
class Meta:
|
|
model = ZoneImageSegment
|
|
fields = ['id', 'zone',
|
|
'segment_order', 'segment_percentage_width']
|
|
|
|
|
|
class HabitatImageSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
image_segments = ZoneImageSegmentSerializer(many=True)
|
|
|
|
class Meta:
|
|
model = HabitatImage
|
|
fields = ['id', 'name', 'image_filename', 'image_segments']
|
|
|
|
|
|
class HabitatSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
images = HabitatImageSerializer(many=True)
|
|
|
|
class Meta:
|
|
model = Habitat
|
|
fields = ['id', 'name', 'images']
|
|
|
|
|
|
class LocationDetailsSerializer(serializers.Serializer):
|
|
ecologic_1 = serializers.CharField(max_length=50)
|
|
ecologic_2 = serializers.CharField(max_length=50)
|
|
code = serializers.CharField(max_length=1)
|
|
name = serializers.CharField(max_length=50)
|
|
|
|
|
|
class PlantSerializer(serializers.HyperlinkedModelSerializer):
|
|
id = serializers.ReadOnlyField()
|
|
water_tolerance = ToleranceLevelSerializer()
|
|
drought_tolerance = ToleranceLevelSerializer()
|
|
frost_tolerance = ToleranceLevelSerializer()
|
|
salinity_tolerance = ToleranceLevelSerializer()
|
|
ecological_regions = EcologicalRegionSerializer(many=True, read_only=True)
|
|
soil_order = SoilOrderSerializer(many=True, read_only=True)
|
|
soil_variants = SoilVariantSerializer(many=True, read_only=True)
|
|
zones = ZoneSerializer(many=True, read_only=True)
|
|
|
|
class Meta:
|
|
model = Plant
|
|
fields = '__all__'
|
|
|
|
|
|
class AddressSerializer(serializers.Serializer):
|
|
full_address = serializers.CharField(max_length=500)
|