Skip to content

Instantly share code, notes, and snippets.

@brunomichetti
Created September 13, 2022 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunomichetti/148f77deadf46b040bc2457f8919030b to your computer and use it in GitHub Desktop.
Save brunomichetti/148f77deadf46b040bc2457f8919030b to your computer and use it in GitHub Desktop.
In [25]: result = User.objects.values_list("id", "email")
In [26]: result
Out[26]: <QuerySet [(34, 'brownandrew@thompson.com'), (35, 'valeriejones@welch.com'), (36, 'vmoran@simmons.net'), (37, 'andrew57@gmail.com'), (31, 'cory37@gmail.com'), (32, 'jackiejohnson@hotmail.com'), (38, 'johnsonaaron@valenzuela.com'), (39, 'karen03@booth.com'), (14, 'jorge1@jorge.com'), (42, 'davisbrittany@mcdaniel-franco.info'), (40, 'warrenjulie@gmail.com'), (2, 'millerlauren@johnson.com'), (3, 'thomas89@spence-collins.com'), (15, 'jorge2@jorge.com'), (33, 'albert65@yahoo.com'), (13, 'bbb@bbb.com'), (29, 'open_dcmkrcb_user@tfbnw.net'), (43, 'chelseanguyen@heath.biz'), (30, 'hoganmichael@henry-valdez.info'), (41, 'fking@gmail.com'), '...(remaining elements truncated)...']>
In [27]: result = User.objects.values("id", "email")
In [28]: result
Out[28]: <QuerySet [{'id': 34, 'email': 'brownandrew@thompson.com'}, {'id': 35, 'email': 'valeriejones@welch.com'}, {'id': 36, 'email': 'vmoran@simmons.net'}, {'id': 37, 'email': 'andrew57@gmail.com'}, {'id': 31, 'email': 'cory37@gmail.com'}, {'id': 32, 'email': 'jackiejohnson@hotmail.com'}, {'id': 38, 'email': 'johnsonaaron@valenzuela.com'}, {'id': 39, 'email': 'karen03@booth.com'}, {'id': 14, 'email': 'jorge1@jorge.com'}, {'id': 42, 'email': 'davisbrittany@mcdaniel-franco.info'}, {'id': 40, 'email': 'warrenjulie@gmail.com'}, {'id': 2, 'email': 'millerlauren@johnson.com'}, {'id': 3, 'email': 'thomas89@spence-collins.com'}, {'id': 15, 'email': 'jorge2@jorge.com'}, {'id': 33, 'email': 'albert65@yahoo.com'}, {'id': 13, 'email': 'bbb@bbb.com'}, {'id': 29, 'email': 'open_dcmkrcb_user@tfbnw.net'}, {'id': 43, 'email': 'chelseanguyen@heath.biz'}, {'id': 30, 'email': 'hoganmichael@henry-valdez.info'}, {'id': 41, 'email': 'fking@gmail.com'}, '...(remaining elements truncated)...']>
In [29]: result = User.objects.only("id", "email")
In [30]: result
Out[30]: <QuerySet [<User: brownandrew@thompson.com>, <User: valeriejones@welch.com>, <User: vmoran@simmons.net>, <User: andrew57@gmail.com>, <User: cory37@gmail.com>, <User: jackiejohnson@hotmail.com>, <User: johnsonaaron@valenzuela.com>, <User: karen03@booth.com>, <User: jorge1@jorge.com>, <User: davisbrittany@mcdaniel-franco.info>, <User: warrenjulie@gmail.com>, <User: millerlauren@johnson.com>, <User: thomas89@spence-collins.com>, <User: jorge2@jorge.com>, <User: albert65@yahoo.com>, <User: bbb@bbb.com>, <User: open_dcmkrcb_user@tfbnw.net>, <User: chelseanguyen@heath.biz>, <User: hoganmichael@henry-valdez.info>, <User: fking@gmail.com>, '...(remaining elements truncated)...']>
In [31]: connection.queries
Out[31]:
[{'sql': 'SELECT "users_user"."id", "users_user"."email" FROM "users_user" LIMIT 21',
'time': '0.009'},
{'sql': 'SELECT "users_user"."id", "users_user"."email" FROM "users_user" LIMIT 21',
'time': '0.007'},
{'sql': 'SELECT "users_user"."id", "users_user"."email" FROM "users_user" LIMIT 21',
'time': '0.000'}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment