1、
def findmtm2(request):
import serializer
import json
# 多对多跨表正向查询
# res = softlist.objects.filter(hostlists__ip="10.116.6.177").values("softname")
res2=softlist.objects.filter(hostlists__ip="10.116.9.233").values_list("softname")
print("res2的数据输出是:",res2)
print("res2的类型是:",type(res2))
for nn in res2:
print(nn,type(nn))
for m in res2:
# print(m,type(m))
for mmm in m:
print(mmm)
return HttpResponse("ok,mtm2 search success!!!")
____________________________
程序运行结果:
res2的数据输出是: <QuerySet [('Acronis Backup',), ('Analytics Instance001',), ('CommCellConsole Instance001',), ('CommServe Instance001',), ('DiagnosticsAndUsageServer Instance001',), ('Java 8 Update 201 (64-bit)',), ('Java SE Development Kit 8 Update 201 (64-bit)',), ('MediaAgent Instance001',), ('MediaAgentCore Instance001',), ('MessageQueue Instance001',), ('Microsoft .NET Core Host - 2.1.16 (x64)',), ('Microsoft .NET Core Host - 2.1.5 (x64)',), ('Microsoft .NET Core Host FX Resolver - 2.1.16 (x64)',), ('Microsoft .NET Core Host FX Resolver - 2.1.5 (x64)',), ('Microsoft .NET Core Runtime - 2.1.16 (x64)',), ('Microsoft .NET Core Runtime - 2.1.5 (x64)',), ('Microsoft ASP.NET Core 2.1.16 Shared Framework (x64)',), ('Microsoft ASP.NET Core 2.1.5 Shared Framework (x64)',), ('Microsoft ASP.NET Core Module',), ('Microsoft Help Viewer 1.1',), '...(remaining elements truncated)...']>
res2的类型是: <class 'django.db.models.query.QuerySet'>
Acronis Backup
Analytics Instance001
CommCellConsole Instance001
CommServe Instance001
DiagnosticsAndUsageServer Instance001
Java 8 Update 201 (64-bit)
Java SE Development Kit 8 Update 201 (64-bit)