UPDATE
This commit is contained in:
@@ -3,10 +3,15 @@ from rest_framework import serializers
|
||||
from location_data.serializers import SoilDepthDataSerializer
|
||||
from irrigation.models import IrrigationMethod
|
||||
from irrigation.serializers import IrrigationMethodSerializer
|
||||
from plant.serializers import PlantSerializer
|
||||
from weather.models import WeatherForecast
|
||||
|
||||
from .models import DEFAULT_SENSOR_DATA_TYPE, DEFAULT_SENSOR_KEY, SensorData
|
||||
from .models import (
|
||||
DEFAULT_SENSOR_DATA_TYPE,
|
||||
DEFAULT_SENSOR_KEY,
|
||||
FarmPlantAssignment,
|
||||
PlantCatalogSnapshot,
|
||||
SensorData,
|
||||
)
|
||||
|
||||
|
||||
class SensorDataUpdateSerializer(serializers.Serializer):
|
||||
@@ -19,7 +24,7 @@ class SensorDataUpdateSerializer(serializers.Serializer):
|
||||
plant_ids = serializers.ListField(
|
||||
child=serializers.IntegerField(),
|
||||
required=False,
|
||||
help_text="لیست شناسه گیاهان مرتبط",
|
||||
help_text="لیست شناسه گیاهان canonical در Backend/plants",
|
||||
)
|
||||
irrigation_method_id = serializers.IntegerField(
|
||||
required=False,
|
||||
@@ -101,17 +106,16 @@ class SensorDataUpdateSerializer(serializers.Serializer):
|
||||
class SensorDataResponseSerializer(serializers.ModelSerializer):
|
||||
"""سریالایزر خروجی برای SensorData."""
|
||||
|
||||
plant_ids = serializers.PrimaryKeyRelatedField(
|
||||
source="plants",
|
||||
many=True,
|
||||
read_only=True,
|
||||
)
|
||||
plant_ids = serializers.SerializerMethodField()
|
||||
irrigation_method_id = serializers.IntegerField(
|
||||
source="irrigation_method.id",
|
||||
read_only=True,
|
||||
allow_null=True,
|
||||
)
|
||||
|
||||
def get_plant_ids(self, obj):
|
||||
return [plant.backend_plant_id for plant in obj.plant_snapshots]
|
||||
|
||||
class Meta:
|
||||
model = SensorData
|
||||
fields = [
|
||||
@@ -172,13 +176,64 @@ class FarmSoilPayloadSerializer(serializers.Serializer):
|
||||
depths = SoilDepthDataSerializer(many=True)
|
||||
|
||||
|
||||
class PlantCatalogSnapshotSerializer(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField(source="backend_plant_id", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = PlantCatalogSnapshot
|
||||
fields = [
|
||||
"id",
|
||||
"backend_plant_id",
|
||||
"name",
|
||||
"slug",
|
||||
"icon",
|
||||
"description",
|
||||
"metadata",
|
||||
"light",
|
||||
"watering",
|
||||
"soil",
|
||||
"temperature",
|
||||
"growth_stage",
|
||||
"growth_stages",
|
||||
"planting_season",
|
||||
"harvest_time",
|
||||
"spacing",
|
||||
"fertilizer",
|
||||
"health_profile",
|
||||
"irrigation_profile",
|
||||
"growth_profile",
|
||||
"is_active",
|
||||
"source_updated_at",
|
||||
"updated_at",
|
||||
]
|
||||
|
||||
|
||||
class FarmPlantAssignmentSerializer(serializers.ModelSerializer):
|
||||
plant_id = serializers.IntegerField(source="plant.backend_plant_id", read_only=True)
|
||||
plant = PlantCatalogSnapshotSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = FarmPlantAssignment
|
||||
fields = [
|
||||
"plant_id",
|
||||
"position",
|
||||
"stage",
|
||||
"metadata",
|
||||
"assigned_at",
|
||||
"updated_at",
|
||||
"plant",
|
||||
]
|
||||
|
||||
|
||||
class FarmDetailSerializer(serializers.Serializer):
|
||||
center_location = FarmCenterLocationSerializer()
|
||||
weather = WeatherForecastDetailSerializer(allow_null=True)
|
||||
sensor_payload = serializers.JSONField()
|
||||
sensor_schema = serializers.JSONField()
|
||||
soil = FarmSoilPayloadSerializer()
|
||||
plant_ids = serializers.ListField(child=serializers.IntegerField())
|
||||
plants = PlantSerializer(many=True)
|
||||
plants = PlantCatalogSnapshotSerializer(many=True)
|
||||
plant_assignments = FarmPlantAssignmentSerializer(many=True)
|
||||
irrigation_method_id = serializers.IntegerField(allow_null=True)
|
||||
irrigation_method = IrrigationMethodSerializer(allow_null=True)
|
||||
created_at = serializers.DateTimeField()
|
||||
|
||||
Reference in New Issue
Block a user