feat: 批次统计数据支持返回source_near
This commit is contained in:
parent
952cdb1bc7
commit
3d6fcfac8a
|
|
@ -1077,6 +1077,15 @@ class BatchStViewSet(CustomListModelMixin, ComplexQueryMixin, CustomGenericViewS
|
||||||
ordering = ["batch"]
|
ordering = ["batch"]
|
||||||
filterset_class = BatchStFilter
|
filterset_class = BatchStFilter
|
||||||
|
|
||||||
|
def add_info_for_list(self, data):
|
||||||
|
if self.request.query_params.get("with_source_near", None) == "yes":
|
||||||
|
batchstIds = [ins["id"] for ins in data]
|
||||||
|
batchlog_qs = BatchLog.objects.filter(target__id__in=batchstIds).values("id", "source", "target")
|
||||||
|
source_data = BatchStSerializer(instance=BatchSt.objects.filter(id__in=[ins["source"] for ins in batchlog_qs]), many=True).data
|
||||||
|
source_data_dict = {ins["id"]: ins for ins in source_data}
|
||||||
|
for item in data:
|
||||||
|
item["source_near"] = [source_data_dict[ins["source"]] for ins in batchlog_qs if ins["target"] == item["id"]]
|
||||||
|
return data
|
||||||
|
|
||||||
class MlogbwViewSet(CustomModelViewSet):
|
class MlogbwViewSet(CustomModelViewSet):
|
||||||
perms_map = {"get": "*", "post": "mlog.update", "put": "mlog.update", "delete": "mlog.update", "patch": "mlog.update"}
|
perms_map = {"get": "*", "post": "mlog.update", "put": "mlog.update", "delete": "mlog.update", "patch": "mlog.update"}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue