feat: enstat2 返回时保留2位小数

This commit is contained in:
caoqianming 2023-08-24 10:28:07 +08:00
parent 909499fc44
commit 6e1ab8a967
1 changed files with 10 additions and 1 deletions

View File

@ -122,4 +122,13 @@ class EnStatSerializer(CustomModelSerializer):
class EnStat2Serializer(CustomModelSerializer):
class Meta:
model = EnStat2
fields = '__all__'
fields = '__all__'
def to_representation(self, instance):
ret = super().to_representation(instance)
my_dic_keys = list(ret.keys())
for key in my_dic_keys:
ret_one_val = ret[key]
if isinstance(ret_one_val, float):
ret[key] = "{:.2f}".format(round(ret_one_val, 2))
return ret