Q查询
查看底层SQL
def showsql():
from django.db import connection
print connection.queries[-1]['sql']
条件与操作
from student.models import *
from django.db.models import Q,F
Stu.objects.filter(Q(sno=1)&Q(sname='zhangsan'))
<QuerySet [<Stu: Stu:zhangsan,88>]>
showsql()
SELECT `t_stu`.`sno`, `t_stu`.`sname`, `t_stu`.`score`, `t_stu`.`created`, `t_stu`.`clazz_id` FROM `t_stu` WHERE (`t_stu`.`sno` = 1 AND `t_stu`.`sname` = 'zhangsan') LIMIT 21
Stu.objects.get(Q(sno=1)&Q(sname='zhangsan'))
<Stu: Stu:zhangsan,88>
showsql()
SELECT `t_stu`.`sno`, `t_stu`.`sname`, `t_stu`.`score`, `t_stu`.`created`, `t_stu`