django shellで実行されるsqlを表示する

QuerySetでちょっと複雑な条件を書いてるときとか、sqlがどうなってるのか確認したい場合がある。
そんなときはdjango-extensionsのshell_plusの--print-sqlオプションを使うと便利。
モデルもpreloadしてくれるのでいちいちimportしなくていい

python manage.py shell_plus --bpython --print-sql
$ python manage.py help shell_plus 
Usage: manage.py shell_plus [options]

Like the 'shell' command but autoloads the models of all installed Django apps.

Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on exception
  --plain               Tells Django to use plain Python, not BPython nor
                        IPython.
  --bpython             Tells Django to use BPython, not IPython.
  --ipython             Tells Django to use IPython, not BPython.
  --notebook            Tells Django to use IPython Notebook.
  --use-pythonrc        Tells Django to execute PYTHONSTARTUP file (BE
                        CAREFULL WITH THIS!)
  --print-sql           Print SQL queries as they're executed
  --dont-load=DONT_LOAD
                        Ignore autoloading of some apps/models. Can be used
                        several times.
  --quiet-load          Do not display loaded models messages
  --version             show program's version number and exit
  -h, --help            show this help message and exit


[https://github.com/django-extensions/django-extensions:title=django-extensions/django-extensions
]

関連 : Djangoでrailsのrake routesみたいな機能 - brainstorm