Created
April 17, 2019 08:47
-
-
Save miodeqqq/3f431bc63334e14d8f6066b1ac047a72 to your computer and use it in GitHub Desktop.
Django raw SQL queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models.expressions import RawSQL | |
from apps.core.models import MyModel | |
sql_query = """SELECT * FROM my_table;""" | |
raw_sql = RawSQL( | |
sql=sql_query, | |
params=[1] | |
) | |
qs = MyModel.objects.filter(myfield__pk__in=raw_sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment