Django查询时候使用sql语句的方式

栏目: Python · 发布时间: 6年前

内容简介:Django orm中使用原生sql查询数据的方式。查询文章列表

Django orm中使用原生 sql 查询数据的方式。

使用extra

查询文章列表

Article.objects.filter(author__name='张三').extra(where=['rank>50'])

使用raw

articles=Article.objects.raw('select * from blog_article')  
for article in articles:  
   print article

自定义sql

from django.db import connection  

cursor = connection.cursor()  
cursor.execute("insert into blog_author(name) VALUES ('lisi')")  
cursor.execute("update blog_author set name='lisi' WHERE name='wangwu'")  
cursor.execute("delete from blog_author where name='lisi'")  
cursor.execute("select * from blog_author")  
cursor.fetchone()  
cursor.fetchall()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Effective JavaScript

Effective JavaScript

David Herman / Addison-Wesley Professional / 2012-12-6 / USD 39.99

"It's uncommon to have a programming language wonk who can speak in such comfortable and friendly language as David does. His walk through the syntax and semantics of JavaScript is both charming and h......一起来看看 《Effective JavaScript》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具