For a Queryset in Django, we can call its method .query to get the raw sql.
for example,
queryset = AModel.objects.all()
print queryset.query
the output could be: SELECT “id”, … FROM “amodel”
But for retrieving a object by “get”, say,
item = AModel.objects.get(id = 100)
how to get the equivalent raw sql? Notice: the item might be None.
The
item = AModel.objects.get(id = 100)equals toThus the executed query equals to
AModel.objects.filter(id = 100)Also, you could check the latest item of
connection.queriesAnd, as FoxMaSk said, install
django-debug-toolbarand enjoy it in your browser.