File: commands.rst

package info (click to toggle)
python-django-debug-toolbar 1%3A6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,052 kB
  • sloc: python: 7,555; javascript: 636; makefile: 67; sh: 16
file content (47 lines) | stat: -rw-r--r-- 1,430 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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