All Unkept
Posted in: Python, Web development, Django  —  May 19, 2012 at 02:12 PM

Reasons to love Django, part x of y

by Luke Plant

I needed to add a boolean field to a model. For many web apps, this typically involves:

  1. modifying the model layer, so that the field becomes available as an attribute on retrieved objects, and can be queried against etc.
  2. creating a database migration script that can be run immediately on the development box, and later for staging and production.
  3. running the migration against the development DB.
  4. updating any admin screens for editing the field.
  5. checking the changes and scripts into source control.
  6. deploying - including pushing source code and running migration scripts etc.

Using Django, from a cold start (no editor/IDE open), this just took me 1 minute 45 seconds of work for steps 1 - 5, and an additional 45 seconds waiting for step 6, total 2 minutes 30 seconds, and I wasn't rushing.

Step 1 is a one line code addition. Pretty much everything else can and should be generated automatically.

Step 2 is taken care of by a one line command using South, as is step 3 and the database part of step 6 (which is run de-rigueur from my deployment scripts).

Step 4 is taken care of by Django's admin, which introspects the model and generates the right form for you.

This is one of the reasons I love Django. It's not so much the time it saves, although that is pretty awesome, it's the tedium it saves.

This is also one of the reasons I'm not very tempted by schema-less or schema-light databases, because with Django a nice strict schema brings so little administrative overhead. I was going to have to add something about the change to the model anyway, even if it was only documentation, and having done that in one place, the other additional changes required by a relational DB with strong schema placed virtually no burden on me.

(Of course, things could be more complex on bigger apps, especially if the table is large or sharded. But then again, there's no reason why rolling out your DB change shouldn't be just as automated - it's only the 'waiting' stage that has to take longer for a simple change like adding a column. If the coding/work part is taking much longer than the above example, your tools probably need fixing or replacing.)

Comments §

blog comments powered by Disqus