Tools of Pro Django developer - aka What powers dinette and almost every app we write.
By : Shabda Raaj
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
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 to manage.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
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. :)
We build Amazing web apps, and we can build it for you. Contact us today.
Related Posts
- __new__() in python
- Introduction to Python Workshop on February 15th, 2013
- Metaclass in Python
- Understanding '*', '*args', '**' and '**kwargs'
- Understanding decorators
Can we help you build amazing apps? Contact us today.
Nice list of django tools, but I think your missing a few things. First off there should be some mention about the environment your working in, any *nix based OS (Ubuntu, Gentoo, OSX, Chrome, etc) is going to open up a lot of tools when your start using the command line. If you're forced to use Windows at least use CYGWIN or something to get these tools they help out a lot. Also GNU Screen should be mentioned as well as virtualenv because they allow you to isolate your environment and keep different processes running (django shell, test, dev server, etc...), along with whatever SCM (git, hg, svn) you use. All of these tools make developing applications with django much more easier, and help you become a more proficient developer.