Create plant display fields on the backend
This commit is contained in:
parent
73e7fe88f8
commit
edd2054763
3 changed files with 41 additions and 16 deletions
|
@ -123,5 +123,32 @@ class Plant(models.Model):
|
||||||
soil_variants = models.ManyToManyField(SoilVariant)
|
soil_variants = models.ManyToManyField(SoilVariant)
|
||||||
zones = models.ManyToManyField(Zone)
|
zones = models.ManyToManyField(Zone)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display_name(self):
|
||||||
|
common_name_str = f' / {str(self.commonname)}' if self.commonname is not None else ''
|
||||||
|
synonym_str = f' / {str(self.synonym)}' if self.synonym is not None else ''
|
||||||
|
return f"{self.name}{common_name_str}{synonym_str}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def display_growth_form(self):
|
||||||
|
growth_form_str = f'{str(self.growth_form)} / ' if self.growth_form is not None else ''
|
||||||
|
return f"{growth_form_str}{self.maxheight} / {self.spacing}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def moisture_preferences(self):
|
||||||
|
return ', '.join([variant.name for variant in self.soil_variants.all()])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def plant_tolerances(self):
|
||||||
|
return f"{self.water_tolerance.level} / {self.drought_tolerance.level} / {self.frost_tolerance.level} / {self.salinity_tolerance.level}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ecosystem_services(self):
|
||||||
|
return f"{str(self.purpose) or ''}"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def carbon_sequestration(self):
|
||||||
|
return ""
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -104,6 +104,13 @@ class PlantSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
soil_variants = SoilVariantSerializer(many=True, read_only=True)
|
soil_variants = SoilVariantSerializer(many=True, read_only=True)
|
||||||
zones = ZoneSerializer(many=True, read_only=True)
|
zones = ZoneSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
|
display_name = serializers.CharField(max_length=300)
|
||||||
|
display_growth_form = serializers.CharField(max_length=300)
|
||||||
|
moisture_preferences = serializers.CharField(max_length=50)
|
||||||
|
plant_tolerances = serializers.CharField(max_length=50)
|
||||||
|
ecosystem_services = serializers.CharField(max_length=200)
|
||||||
|
carbon_sequestration = serializers.CharField(max_length=50)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Plant
|
model = Plant
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
|
@ -17,23 +17,14 @@ export default function ResultsStep(props) {
|
||||||
|
|
||||||
const getTableRows = () => {
|
const getTableRows = () => {
|
||||||
return props.plants.map((plant) => {
|
return props.plants.map((plant) => {
|
||||||
|
|
||||||
const name = `${plant.name}/${plant.commonname}/${plant.synonym}`;
|
|
||||||
const growthForm = `${plant.growth_form}/${plant.maxheight}/${plant.spacing}`;
|
|
||||||
const moisturePreferences = `${plant.soil_variants.map((variant) => variant.name).join(', ')}`;
|
|
||||||
const plantTolerances = `${plant.water_tolerance.level}/${plant.drought_tolerance.level}/${plant.frost_tolerance.level}/${plant.salinity_tolerance.level}`;;
|
|
||||||
const ecosystemServices = `${plant.purpose}`;
|
|
||||||
const carbonSequestration = ``
|
|
||||||
const plantingStage = `${plant.stage}`
|
|
||||||
|
|
||||||
return createData(
|
return createData(
|
||||||
name,
|
plant.display_name,
|
||||||
growthForm,
|
plant.display_growth_form,
|
||||||
moisturePreferences,
|
plant.moisture_preferences,
|
||||||
plantTolerances,
|
plant.plant_tolerances,
|
||||||
ecosystemServices,
|
plant.ecosystem_services,
|
||||||
carbonSequestration,
|
plant.carbon_sequestration,
|
||||||
plantingStage
|
plant.stage
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue