diff --git a/apps/wpm/views.py b/apps/wpm/views.py index 1a0fc458..29e2074f 100644 --- a/apps/wpm/views.py +++ b/apps/wpm/views.py @@ -1077,6 +1077,15 @@ class BatchStViewSet(CustomListModelMixin, ComplexQueryMixin, CustomGenericViewS ordering = ["batch"] 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): perms_map = {"get": "*", "post": "mlog.update", "put": "mlog.update", "delete": "mlog.update", "patch": "mlog.update"}