Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In [1]: from django.db import reset_queries, connection
In [2]: target = Target.objects.first()
In [3]: connection.queries
Out[3]:
[{'sql': 'SELECT "targets_target"."id", "targets_target"."user_id", "targets_target"."title", "targets_target"."topic", "targets_target"."radius_in_mts", "targets_target"."location"::bytea, "targets_target"."created_at", "targets_target"."updated_at" FROM "targets_target" ORDER BY "targets_target"."id" ASC LIMIT 1',
'time': '0.009'}]
In [4]: target.user_id
Out[4]: 40
In [5]: connection.queries
Out[5]:
[{'sql': 'SELECT "targets_target"."id", "targets_target"."user_id", "targets_target"."title", "targets_target"."topic", "targets_target"."radius_in_mts", "targets_target"."location"::bytea, "targets_target"."created_at", "targets_target"."updated_at" FROM "targets_target" ORDER BY "targets_target"."id" ASC LIMIT 1',
'time': '0.009'}]
In [6]: target.user.id
Out[6]: 40
In [7]: connection.queries
Out[7]:
[{'sql': 'SELECT "targets_target"."id", "targets_target"."user_id", "targets_target"."title", "targets_target"."topic", "targets_target"."radius_in_mts", "targets_target"."location"::bytea, "targets_target"."created_at", "targets_target"."updated_at" FROM "targets_target" ORDER BY "targets_target"."id" ASC LIMIT 1',
'time': '0.009'},
{'sql': 'SELECT "targets_user"."id", "targets_user"."password", "targets_user"."last_login", "targets_user"."is_superuser", "targets_user"."first_name", "targets_user"."last_name", "targets_user"."is_staff", "targets_user"."is_active", "targets_user"."date_joined", "targets_user"."email", "targets_user"."name", "targets_user"."username", "targets_user"."date_of_birth", "targets_user"."zodiac_sign" FROM "targets_user" WHERE "targets_user"."id" = 40 LIMIT 21',
'time': '0.014'}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment