- extra
Book.objects.filter(publisher__name='人民邮电出版社').extra(where=['price>50'])
- raw
books=Book.objects.raw('select * from hello_book') for book in books: print book
- 自定义sql
from django.db import connection cursor = connection.cursor() cursor.execute("insert into hello_author(name) VALUES ('郭敬明')") cursor.execute("update hello_author set name='韩寒' WHERE name='郭敬明'") cursor.execute("delete from hello_author where name='韩寒'") cursor.execute("select * from hello_author") cursor.fetchone() cursor.fetchall()
1.Django数据库操作之SQL语句
最新推荐文章于 2024-07-17 21:01:28 发布