Add all fields to plant serializer
This commit is contained in:
parent
cc3c3e7e9a
commit
72110cd19f
1 changed files with 34 additions and 2 deletions
|
@ -1,9 +1,41 @@
|
|||
from rest_framework import serializers
|
||||
from right_tree.api.models import Plant
|
||||
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()
|
||||
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
|
||||
fields = ['id', 'name']
|
||||
fields = '__all__'
|
||||
|
|
Loading…
Reference in a new issue