From 68933e3e161f1fe30c8ff7c6af48b030bf48bfaf Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 11 Apr 2024 16:57:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20EnvDataSerializer=20round=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enp/serializers.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/enp/serializers.py b/apps/enp/serializers.py index f6ccb909..50446648 100644 --- a/apps/enp/serializers.py +++ b/apps/enp/serializers.py @@ -126,6 +126,12 @@ class EnvDataSerializer(CustomModelSerializer): model = EnvData fields = "__all__" + def to_representation(self, instance): + representation = super().to_representation(instance) + for field_name in ("dust_rtd", "dust_zs", "temperature", "pressure", "speed", "humidity", "flux", "pm25", "pm10", "tsp", "wind_speed", "so2_rtd", "so2_zs", "nox_rtd", "nox_zs", "o2"): + representation[field_name] = round(representation[field_name], 4) + return representation + class DrainEquipEnvSerializer(CustomModelSerializer): equipment_number = serializers.CharField(source="equipment.number", read_only=True)