From 6e4b8d95b8bcdeeab039f0a0c7e6d6833cd8685e Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 27 Oct 2013 14:41:22 +0100 Subject: Migrate info from README to docs. --- docs/commands.rst | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'docs/commands.rst') diff --git a/docs/commands.rst b/docs/commands.rst index 675c188..1d81a05 100644 --- a/docs/commands.rst +++ b/docs/commands.rst @@ -1,2 +1,47 @@ Commands ======== + +The Debug Toolbar currently provides one Django management command. + +``debugsqlshell`` +----------------- + +This command starts an interactive Python shell, like Django's built-in +``shell`` management command. In addition, each ORM call that results in a +database query will be beautifully output in the shell. + +Here's an example:: + + >>> from page.models import Page + >>> ### Lookup and use resulting in an extra query... + >>> p = Page.objects.get(pk=1) + SELECT "page_page"."id", + "page_page"."number", + "page_page"."template_id", + "page_page"."description" + FROM "page_page" + WHERE "page_page"."id" = 1 + + >>> print p.template.name + SELECT "page_template"."id", + "page_template"."name", + "page_template"."description" + FROM "page_template" + WHERE "page_template"."id" = 1 + + Home + >>> ### Using select_related to avoid 2nd database call... + >>> p = Page.objects.select_related('template').get(pk=1) + SELECT "page_page"."id", + "page_page"."number", + "page_page"."template_id", + "page_page"."description", + "page_template"."id", + "page_template"."name", + "page_template"."description" + FROM "page_page" + INNER JOIN "page_template" ON ("page_page"."template_id" = "page_template"."id") + WHERE "page_page"."id" = 1 + + >>> print p.template.name + Home -- cgit v1.2.3