fix: mpointserializer获取last_data优化
This commit is contained in:
parent
499e5732aa
commit
643efa448e
|
@ -25,10 +25,20 @@ class MpointSerializer(CustomModelSerializer):
|
||||||
read_only_fields = EXCLUDE_FIELDS + ["belong_dept", "cate"]
|
read_only_fields = EXCLUDE_FIELDS + ["belong_dept", "cate"]
|
||||||
|
|
||||||
def get_last_data(self, obj):
|
def get_last_data(self, obj):
|
||||||
return cache.get(Mpoint.cache_key(obj.code), {}).get('last_data', {})
|
cache_mp = cache.get(Mpoint.cache_key(obj.code))
|
||||||
|
if isinstance(cache_mp, dict):
|
||||||
|
last_data = cache_mp.get('last_data', {})
|
||||||
|
else:
|
||||||
|
last_data = {}
|
||||||
|
return last_data
|
||||||
|
|
||||||
def get_gather_state(self, obj):
|
def get_gather_state(self, obj):
|
||||||
return cache.get(Mpoint.cache_key(obj.code), {}).get('gather_state', -2)
|
cache_mp = cache.get(Mpoint.cache_key(obj.code))
|
||||||
|
if isinstance(cache_mp, dict):
|
||||||
|
gather_state = cache_mp.get('gather_state', -2)
|
||||||
|
else:
|
||||||
|
gather_state = -2
|
||||||
|
return gather_state
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
if "material" in attrs and attrs["material"]:
|
if "material" in attrs and attrs["material"]:
|
||||||
|
|
Loading…
Reference in New Issue