Tools of Pro Django developer – aka What powers dinette and almost every app we write.

There are some tools and apps which we use with almost all apps we write, and in particular which, we used for dinette. Here they are broken into useful during development, and (also) useful post development.

During Development

  1. Ipython and ipdb
  2. South
  3. Django test utils
  4. Django extensions
  5. Django debug toolbar
IPYTHON AND IPDB

Ipython is a enhanced shell for python. Ipdb similarly add extra capacity to the builtin pdb debugger. It is extremely convenient to drop into a ipython shell right where a complex piece of code is being hit.

from IPython.Shell import IPShellEmbed ipython = IPShellEmbed() ipython() 

Of course this does not allow you to step through, so if you want to step through your code, you need to do

import ipdb ipdb.set_trace() 

Of course, you can just do pdb.set_trace(), but with tab completion and syntax highlighting, using ipdb is a no brainer.

SOUTH

South adds schema migration to Django. It has lot of advanced options, but just three command will get you along way.

Convert a normal app to use the south way.

./manage.py convert_to_south 

Once you have made any changes to your apps model, write a new migration which can update the database to latest models.py

./manage.py startmigration appname nameofmigration --auto 

Once you have written a migration, write a command to update the db.

./manage.py migrate appanme  
DJANGO TEST UTILS

When you are running tests, a huge time sink is the time spent dropping and recreating tests. You might add just a single test, and the default Django testrunner will spend a huge time recreating the database. Enter manage.py quicktest which reuses databases between test runs. One of the side effects of this is that if you modify models.py between test runs you should manually recreate the database.

The tests (or whatever little of it exists) for Dinette were written using testutils’ testmaker.

DJANGO EXTENSIONS

Django extensions, (earlier Django command extensions) is a app which adds extra commands tomanage.py. It has lot of goodies, but just ./manage.py shell_plus makes it worthwhile. (It imports all the models from all the apps automatically).

Get the full list at Github

DJANGO DEBUG TOOLBAR

I do not personally use it but some people on our team swear by it.

After development

  1. Django-pagination
  2. sorl-thumbnails
  3. django-compressor
  4. Haystack
DJANGO-PAGINATION

I have decided on a standard way to build apps which need pagination. a. Build apps without pagination. b. The night before release spend an hour and add pagination to all pages. Really this is all you need

{% load pagination tags %} {% autopaginate queryset %} .... {% paginate %} 

There is no change required to the views.

SORL-THUMBNAILS

To thumbnail an image.

{% thumbnail image size %} 

“Things should be as simple as possible, but not simpler.”

DJANGO-COMPRESSOR

During development we work with multiple unminified js and css files. Django-compressor takes care of minifying and compressing it when we deploy. All we need to do is,

{% compress css %} ... all css files .... {% endcompress %}   {% compress js %} ... all js files .... {% endcompress %} 
HAYSTACK

Haystack is “modular search for Django”. It make writing search views as easy as writing the admin. You declaratively tell what fields you want to search on, and Haystack can take care of creating and updating the index, and providing a generic view to handle the search. Check a search view written using Haystack http://uswaretech.com/forum/search/?q=django


To everyone who contributed to these apps, thanks. Django development won’t be the same without these great tools. This post was inspired by Kevin Fricovsky’s post post, The apps that power Django-Mingus and is stolen about 50% from there. Thanks. :)

No comments:

Post a Comment