def get_env_node(self, job): # this function is required to apply 'parent=None' filter because env_node children will be # populated by the EnvNodeNestedSerializer objs = EnvNodeModel.objects.filter(job=job.id, parent=None).all() if isinstance(self, JobSimpleSerializer): return EnvNodeSimpleSerializer(objs, many=True).data else: return EnvNodeNestedSerializer(objs, many=True).data
def get_env_node(self, cmp): objs = [] visited = set() for job in cmp.pt_get_jobs(): #for obj in EnvNodeModel.objects.filter(job=job.id, parent=None).all(): for obj in job.env_nodes.all().only("job_id", "parent", "name"): if obj.parent is not None or obj.name in visited: continue visited.add(obj.name) objs.append(obj) return EnvNodeSimpleSerializer(objs, many=True).data
def get_env_node(self, cmp): objs = [] visited = set() for job in cmp.jobs.all(): for obj in EnvNodeModel.objects.filter(job=job.id, parent=None).all(): if obj.name in visited: continue visited.add(obj.name) objs.append(obj) return EnvNodeSimpleSerializer(objs, many=True).data