Django資料庫的操作

django orm的操作網路上已經有很多資料了。這邊要提的是直接下sql的指令的方法。其實也相當單純。如下所示:

from django.db import connection
...
with connection.cursor() as cursor:
cursor.execute("這裡放入SQL的指令") # 如select from ...
rtn_data = cursor.fetchall()
...

ref: https://docs.djangoproject.com/en/1.10/topics/db/sql/

Show your support

Clapping shows how much you appreciated Epicure1709’s story.