right-tree/backend/right_tree/api/serializers.py

42 lines
1.3 KiB
Python
Raw Normal View History

from rest_framework import serializers
2021-10-20 12:37:45 +13:00
from right_tree.api.models import Plant, ToleranceLevel, SoilOrder, SoilVariant, EcologicalRegion
class ToleranceLevelSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = ToleranceLevel
fields = ['level']
class EcologicalRegionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = EcologicalRegion
fields = ['name']
class SoilOrderSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = SoilOrder
fields = ['name']
class SoilVariantSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = SoilVariant
fields = ['name']
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)
class Meta:
model = Plant
2021-10-20 12:37:45 +13:00
fields = '__all__'