« Using pdb to debug management commands and unit tests (Debugging Django Series,Part 4) | Getting started with Pinax »
This is a screencast on the Django Command Extensions project. It is one of my favorite third party apps, and it gets installed in every Django environment I work in. It provides a plethora of useful manage.py commands, and a couple other little goodies as well.
Before you get started using these things, there are a couple of packages you need to install. The first is Graphviz which is a really nice toolkit for graph visualization. The other is Werkzeug which is a little python web framework with an amazing debugger that we'll be using. There can easily be installed:
apt-get install graphviz
easy_install Werkzeug
A high-res version of the video is available here (mov 21MB)
Django Command Extensions from Eric Holscher on Vimeo.
The website for the django extensions has a pretty good list of all of the commands that are available. Below I will just write about the way to use some of them that isn't well documented or a bit different or unclear.
As a note, for things that output something to the screen, you can redirect that output to a file really easily. For example:
./manage.py dumpscript blog > blog.py
redirects the output to blog.py.
The command extensions site has a list of output formats for export_emails here. Which is really useful.
The command for graphviz is
/manage.py graph_models auth blog |dot -Tpng -o test.png
The output of graphviz is awesome. There are ways that you can hook this up to a url in your URLConf so that it will be regenerated whenever someone requests it (for data that changes often). That is a really nice feature for data that is changing a lot, where someone is watching over your work (school etc.).
Just to note, runserver_plus requires that you be running DEBUG = True, and that your IP Adress is in INTERNAL_IPS, look at my (screencast)[http://ericholscher.com/blog/2008/aug/28/screencast-debugging-django-error-page/] here for a full explanation of this, and more!
Things that weren't covered in the screencast include sqldiff which is still halfway working, and provides a diff against what your model and the current database look like. create_app and create_command are things that just flesh out the directory structure for a new app or management command. create_superuser creates a new supersuer for you. generate_secret_key gives you a new secret key. passwd allows you to easily change a users password. reset_db resets your current database.
Thanks for watching, and stay tuned for more screencasts (and other content too ;))
Posted at 7:01 p.m. on September 12, 2008
Comments: 9
Tags: django , management commands , screencast
4 days Ago (Comments: 4)
Debugging Django in Production Environments
4 days, 13 hours Ago (Comments: 8)
Should reusable apps have templates?
5 days, 14 hours Ago (Comments: 3)
6 days, 14 hours Ago (Comments: 11)
Great spirits have always found violent opposition from mediocrities. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence.
- Unknown


Comments
1 Doug Napoleone says...
Fantastic! thanks for putting this together! any plans on covering some of the other commands?
Posted at 5:04 a.m. on September 13, 2008
2 Yousef Ourabi says...
Great screencast, graph_models is really cool.
Posted at 5:08 a.m. on September 13, 2008
3 Eric Holscher says...
@Doug Not really. Those pretty much stand on their own. I'm thinking about maybe doing some that are builtin to Django, like inspectdb and databrowse, because those are really neat :)
I have a couple other ideas as well, but suggestions are always welcome.
Posted at 5:59 a.m. on September 13, 2008
4 Nick says...
I failed to install GraphViz on windows. Developers say that they doesn't have any windows machines, so you need to compile it by yourself.
As far as I know a lot of people on the internet complains about that.
Posted at 8:34 a.m. on September 13, 2008
5 newman says...
Great screencast Eric. I've used the extensions on a few projects but never knew that some of these commands were available. My fault for not checking the docs.
Posted at 12:36 p.m. on September 13, 2008
6 trbs says...
FYI: You don't have to pipe the output of graph_models if you want to create an output image. There are two optional options for the graph_model commands: -o filename.ext # specify output image -l layout_name # specify dotty layout name
Example: ./manage.py graph_models -o test.png auth blog
Posted at 1:05 p.m. on September 13, 2008
7 trbs says...
Great screencast btw :)
Love these series and i think they help a lot of people.
Regards, trbs
Posted at 1:06 p.m. on September 13, 2008
8 Empty says...
Wow, excellent work Eric. You did an awesome job on this. Any chance we would link to this post from the Django Extensions project page? FYI, recently we've been focussing on template tags, context processors, custom db fields and stuff like that. So there's some really cool in there just added. My favorite recent additions are clean_pyc and compile_pyc as well as the truncate_letters filter.
Posted at 3:56 p.m. on September 13, 2008
9 sean says...
great screencast, but it's kinda hard to use the graph_model commond on windows platform. any guide on how to install the required components?
Posted at 2:06 a.m. on October 1, 2008