Sep 12

Screencast: Django Command Extensions

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.

Setup

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

Video and Download

A high-res version of the video is available here (mov 21MB)


Command Extensions from Eric Holscher on Vimeo.

Writeup

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 ;))


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

10 Paul Egges says...

Once again an awesome job. I think your tutorials are great aid in making us all a lot more efficient in writing Django apps.

Posted at 10:34 p.m. on November 21, 2008

11 sage says...

How to install dot/graphviz for windows plateform :

1) Go to http://www.graphviz.org/Download_windows.php 2) Download the installer 3) Double-click on the installer in order to install what should be installed 4) Click next several times 5) That's it

(I use dot/graphiz for years on windows, and it has always been like this, expect installer was .exe, and now it's a .msi)

Using graphviz :

Let's suppose you've got a example.dot file (containing a diagram description) :

dot -Tpng -oexample.png example.dot

you now have a example.png

Posted at 1:58 a.m. on January 12, 2009

Comment are disabled for this post.