Skip to content

Instantly share code, notes, and snippets.

@nnja
Created October 1, 2018 06:28
Show Gist options
  • Save nnja/36352d940163b3b57513819988a8b781 to your computer and use it in GitHub Desktop.
Save nnja/36352d940163b3b57513819988a8b781 to your computer and use it in GitHub Desktop.
Show django database queries from the shell
In [2]: tweet = Tweet.objects.get(id=8)
In [3]: from django.db import connection
In [4]: connection.queries
Out[4]:
[{'sql': 'SELECT "tweeter_tweet"."id", "tweeter_tweet"."user_id", "tweeter_tweet"."text", "tweeter_tweet"."timestamp" FROM "tweeter_tweet" WHERE "tweeter_tweet"."id" = 8',
'time': '0.001'}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment