def
tt(request):
print
(
'1对多正向查找'
.center(
40
,
'-'
))
obj
=
models.Host.objects.
filter
(nid__gt
=
1
)
print
(obj[
0
].nid,obj[
0
].hostname,obj[
0
].b.caption)
print
(
'过滤条件'
.center(
40
,
'-'
))
obj
=
models.Business.objects.
filter
(caption__contains
=
'SALE'
).first()
print
(obj.
id
,obj.caption)
obj
=
models.Business.objects.
all
().values(
'id'
,
'caption'
)
print
(obj, obj.order_by(
'id'
).reverse())
obj
=
models.Application.objects.
filter
(name__exact
=
'SQL Server'
).values(
'name'
,
'r__hostname'
,
'r__nid'
)
print
(obj)
print
(
'1对多反向查找'
.center(
40
,
'-'
))
obj
=
models.Business.objects.
all
().values(
'id'
,
'caption'
,
'host__ip'
,
'host__hostname'
)
print
(obj[
0
])
print
(
'多对多正向查找'
.center(
40
,
'-'
))
obj
=
models.Application.objects.
all
().first()
print
(obj.name, obj.r.
all
()[
0
].hostname)
print
(
'多对多反向查找'
.center(
40
,
'-'
))
obj
=
models.Host.objects.
all
().
filter
(nid__gt
=
1
).values(
'nid'
,
'application__name'
).first()
print
(obj)
return
HttpResponse(
'ok'
)