[Answered ]-Django Rest Framework complex SQL query

1👍

You can use the raw function to make it

Model.objects.raw("WRITE YOUR SQL HERE")
👤Ayman

0👍

You can use cursor connection for direct execute SQL query.

from django.db import connection

def my_query(self):
    with connection.cursor() as cursor:
    cursor.execute("UPDATE bar SET foo = 1 WHERE baz = %s", [self.baz])
    cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz])
    row = cursor.fetchall()

return row
👤Abhi

Leave a comment