django orm和sql查询转换
时间:2011-02-17
来源:互联网
在django中
有什么方法 可以把用sql语句 得到的结果:一个tuple,转换成django.db.models.query.QuerySet,这中类型吗?就是直接用django的orm从数据库中取到的数据
如
>>>node=cartree.objects.filter(parentid=-100)
>>> node
[<cartree: -100 监控中心 -100>, <cartree: 1 汇博 -100>]
>>> type(node)
<class 'django.db.models.query.QuerySet'>
>>> n=cursor.execute("select a.nodeid,a.nodename,a.userphone,a.username,'true',b.locate,b.speed,b.direction,b.status,b.gps_time from carinfo a join carlast b where a.equid=b.equid;")
>>> nodeinfo=cursor.fetchall()
>>> nodeinfo
((1000L, '\xe8\xb1\xabEB7822', 2147483647L, '\xe7\x87\x95\xe8\x8e\x8e', 'true', '36.060108,114.201501', 0, 251, 'fffffbff', datetime.datetime(2011, 2, 17, 13, 24, 48)),)
>>> type(nodeinfo)
<type 'tuple'>
有什么方法 可以吧下面这中方式返回的数据 转换为上面那种格式的吗?
有什么方法 可以把用sql语句 得到的结果:一个tuple,转换成django.db.models.query.QuerySet,这中类型吗?就是直接用django的orm从数据库中取到的数据
如
>>>node=cartree.objects.filter(parentid=-100)
>>> node
[<cartree: -100 监控中心 -100>, <cartree: 1 汇博 -100>]
>>> type(node)
<class 'django.db.models.query.QuerySet'>
>>> n=cursor.execute("select a.nodeid,a.nodename,a.userphone,a.username,'true',b.locate,b.speed,b.direction,b.status,b.gps_time from carinfo a join carlast b where a.equid=b.equid;")
>>> nodeinfo=cursor.fetchall()
>>> nodeinfo
((1000L, '\xe8\xb1\xabEB7822', 2147483647L, '\xe7\x87\x95\xe8\x8e\x8e', 'true', '36.060108,114.201501', 0, 251, 'fffffbff', datetime.datetime(2011, 2, 17, 13, 24, 48)),)
>>> type(nodeinfo)
<type 'tuple'>
有什么方法 可以吧下面这中方式返回的数据 转换为上面那种格式的吗?
作者: nothingsss 发布时间: 2011-02-17
那为什么不用ORM?
作者: iambic 发布时间: 2011-02-17
orm怎么实现join查询阿,我不知道,orm可以实现复杂的查询吗?
作者: nothingsss 发布时间: 2011-02-17
n=cursor.execute("select a.nodeid,a.nodename,a.userphone,a.username,'true',b.locate,b.speed,b.direction,b.status,b.gps_time from carinfo a join carlast b where a.equid=b.equid;")
就上面这个语句,字段,语句里就有,你看看怎么实现orm查询,本人在摸索中谢谢指点
就上面这个语句,字段,语句里就有,你看看怎么实现orm查询,本人在摸索中谢谢指点
作者: nothingsss 发布时间: 2011-02-17
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28