UPDATE
This commit is contained in:
+12
-2
@@ -7,6 +7,7 @@ from django.db import transaction
|
||||
from location_data.models import SoilLocation
|
||||
from location_data.serializers import SoilDepthDataSerializer
|
||||
from location_data.tasks import fetch_soil_data_for_coordinates
|
||||
from irrigation.serializers import IrrigationMethodSerializer
|
||||
from plant.serializers import PlantSerializer
|
||||
from weather.services import update_weather_for_location
|
||||
from weather.models import WeatherForecast
|
||||
@@ -25,7 +26,11 @@ class ExternalDataSyncError(Exception):
|
||||
|
||||
def get_farm_details(farm_uuid: str):
|
||||
farm = (
|
||||
SensorData.objects.select_related("center_location", "weather_forecast")
|
||||
SensorData.objects.select_related(
|
||||
"center_location",
|
||||
"weather_forecast",
|
||||
"irrigation_method",
|
||||
)
|
||||
.prefetch_related("plants", "center_location__depths")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
@@ -53,7 +58,6 @@ def get_farm_details(farm_uuid: str):
|
||||
metric_sources[key] = "sensor"
|
||||
|
||||
return {
|
||||
"farm_uuid": farm.farm_uuid,
|
||||
"center_location": {
|
||||
"id": center_location.id,
|
||||
"lat": center_location.latitude,
|
||||
@@ -69,6 +73,12 @@ def get_farm_details(farm_uuid: str):
|
||||
},
|
||||
"plant_ids": list(farm.plants.values_list("id", flat=True)),
|
||||
"plants": PlantSerializer(farm.plants.all(), many=True).data,
|
||||
"irrigation_method_id": farm.irrigation_method_id,
|
||||
"irrigation_method": (
|
||||
IrrigationMethodSerializer(farm.irrigation_method).data
|
||||
if farm.irrigation_method
|
||||
else None
|
||||
),
|
||||
"created_at": farm.created_at,
|
||||
"updated_at": farm.updated_at,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user