64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
from rest_framework import serializers
|
|
|
|
from .models import IrrigationMethod
|
|
|
|
|
|
class IrrigationMethodSerializer(serializers.ModelSerializer):
|
|
"""سریالایزر خروجی / ورودی برای IrrigationMethod."""
|
|
|
|
class Meta:
|
|
model = IrrigationMethod
|
|
fields = [
|
|
"id",
|
|
"name",
|
|
"category",
|
|
"description",
|
|
"water_efficiency_percent",
|
|
"water_pressure_required",
|
|
"flow_rate",
|
|
"coverage_area",
|
|
"soil_type",
|
|
"climate_suitability",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
read_only_fields = ["id", "created_at", "updated_at"]
|
|
|
|
|
|
class IrrigationRecommendRequestSerializer(serializers.Serializer):
|
|
"""سریالایزر ورودی برای درخواست توصیه آبیاری."""
|
|
|
|
farm_uuid = serializers.CharField(required=False, help_text="شناسه یکتای مزرعه (اجباری)")
|
|
sensor_uuid = serializers.CharField(required=False, help_text="نام قدیمی برای farm_uuid")
|
|
plant_name = serializers.CharField(required=False, allow_blank=True, help_text="نام گیاه")
|
|
growth_stage = serializers.CharField(required=False, allow_blank=True, help_text="مرحله رشد گیاه")
|
|
irrigation_method_name = serializers.CharField(
|
|
required=False, allow_blank=True, help_text="نام روش آبیاری"
|
|
)
|
|
query = serializers.CharField(required=False, allow_blank=True, help_text="سوال اختیاری")
|
|
|
|
def validate(self, attrs):
|
|
farm_uuid = attrs.get("farm_uuid") or attrs.get("sensor_uuid")
|
|
if not farm_uuid:
|
|
raise serializers.ValidationError({"farm_uuid": "farm_uuid الزامی است."})
|
|
attrs["farm_uuid"] = farm_uuid
|
|
return attrs
|
|
|
|
|
|
class IrrigationPlanSerializer(serializers.Serializer):
|
|
"""سریالایزر خروجی برای پلن توصیه آبیاری."""
|
|
|
|
frequencyPerWeek = serializers.IntegerField(help_text="تعداد دفعات آبیاری در هفته")
|
|
durationMinutes = serializers.IntegerField(help_text="مدت هر بار آبیاری به دقیقه")
|
|
bestTimeOfDay = serializers.CharField(help_text="بهترین زمان آبیاری")
|
|
moistureLevel = serializers.IntegerField(help_text="سطح رطوبت مطلوب خاک به درصد")
|
|
warning = serializers.CharField(help_text="هشدار یا توصیه مهم", allow_blank=True)
|
|
|
|
|
|
class IrrigationRecommendResponseSerializer(serializers.Serializer):
|
|
"""سریالایزر خروجی برای ریسپانس توصیه آبیاری."""
|
|
|
|
code = serializers.IntegerField()
|
|
msg = serializers.CharField()
|
|
data = serializers.DictField(child=serializers.JSONField())
|