[django] How to implement native sql under the ORM framework of django

Preface: How does the orm under django implement native sql statements

# 需求: 执行原生sql
 
from myapp import models
from django.http import JsonResponse
from django.db.models import Count,F
 
ret = models.Book.objects.raw("select * from book")
for i in ret:
    print(i.title)
 
 
 

 

 

form django.db import connection
cursor = connection.cursor()
cursor.excute("select * from book;")
cusor.fetchall()

Guess you like

Origin blog.csdn.net/legend818/article/details/131091630