https://blog.csdn.net/weixin_36236774/article/details/112933058
queryset 查询结果集
遍历queryset 之后,可以直接获取当前对象的数据,item.ip.all() 获取的是queryset,_ip.x 可以直接获取数据,_ip 类型 <class 'monitoring.models.cloudServer'>
def list(self, request): for item in alertPolicies.objects.all(): _info = {} for _ip in item.ip.all(): _process_name = [] for process in _ip.processgroup_set.all(): _process_name = [ _process.get('process_name') for _process in process.processlist_set.values('process_name') ] _info[_ip.inner_ip_address] = _process_name print(_info)