What is the best way to access stored procedures in Django's ORM

前端 未结 7 1190
轻奢々
轻奢々 2020-12-02 08:44

I am designing a fairly complex database, and know that some of my queries will be far outside the scope of Django\'s ORM. Has anyone integrated SP\'s with Django\'s ORM suc

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 09:32

    You have to use the connection utility in Django:

    from django.db import connection
    
    with connection.cursor() as cursor:
        cursor.execute("SQL STATEMENT CAN BE ANYTHING")
        data = cursor.fetchone()
    

    If you are expecting more than one row, use cursor.fetchall() to fetch a list of them.

    More info here: http://docs.djangoproject.com/en/dev/topics/db/sql/

提交回复
热议问题