2021-10-07 08:59:57 +13:00
|
|
|
from rest_framework import serializers
|
2021-10-22 16:01:38 +13:00
|
|
|
from right_tree.api.models import Plant, ToleranceLevel, SoilOrder, SoilVariant, EcologicalRegion, EcologicalDistrictLayer
|
2021-10-20 12:37:45 +13:00
|
|
|
|
|
|
|
|
|
|
|
class ToleranceLevelSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = ToleranceLevel
|
|
|
|
fields = ['level']
|
|
|
|
|
|
|
|
|
|
|
|
class EcologicalRegionSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = EcologicalRegion
|
|
|
|
fields = ['name']
|
|
|
|
|
|
|
|
|
2021-10-22 16:01:38 +13:00
|
|
|
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']
|
|
|
|
|
|
|
|
|
2021-10-20 12:37:45 +13:00
|
|
|
class SoilOrderSerializer(serializers.HyperlinkedModelSerializer):
|
2021-10-22 16:01:38 +13:00
|
|
|
soil_name = serializers.CharField(max_length=50, source='name')
|
|
|
|
soil_code = serializers.CharField(max_length=1, source='code')
|
|
|
|
|
2021-10-20 12:37:45 +13:00
|
|
|
class Meta:
|
|
|
|
model = SoilOrder
|
2021-10-22 16:01:38 +13:00
|
|
|
fields = ['soil_name', 'soil_code']
|
2021-10-20 12:37:45 +13:00
|
|
|
|
|
|
|
|
|
|
|
class SoilVariantSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = SoilVariant
|
|
|
|
fields = ['name']
|
|
|
|
|
2021-10-07 08:59:57 +13:00
|
|
|
|
2021-10-22 16:01:38 +13:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
2021-10-07 08:59:57 +13:00
|
|
|
class PlantSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
id = serializers.ReadOnlyField()
|
2021-10-20 12:37:45 +13:00
|
|
|
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)
|
2021-10-07 08:59:57 +13:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Plant
|
2021-10-20 12:37:45 +13:00
|
|
|
fields = '__all__'
|
2021-10-22 16:01:38 +13:00
|
|
|
|
|
|
|
|
|
|
|
class AddressSerializer(serializers.Serializer):
|
|
|
|
full_address = serializers.CharField(max_length=500)
|