Entries Tagged 'Django' ↓

Django’s lack of database upgrade features

Enjoying your holiday?  Apart from enjoying some time off and doing a bit of work (things never stop when you’re self-employed!) I’ve started playing with Django, which is something I’ve wanted to do for a long time.  Aside from being curious about Symfony-Rails-Django and which is best (I like absolutes, OK?) and being very keen on anything Simon Willison’s had a hand in (FormProcessor was an inspired design), I’m hoping it will allow me to write a simple CMS for a Christian group that I volunteered to set up a website for (long story there… let’s just say requirements have grown from the 3 page static site, and I don’t want to spend hours of my life changing content!).

From teaching programming to physics students I have some knowledge of Python, so that’s a good start.

When doing quick or small projects I don’t design the database fully beforehand.  I should, but often that would take longer than building the app.  Instead, I set it up with the perceived needs, and refactor as I go.  This is fine for my usual PHP development, and refining and syncing from MySQL Workbench or similar is fine.  However…

Django trumpets the benefit of not needing to write SQL to create the tables, as they’re defined in the Python code.  I am skeptical because as I’ve already mentioned I use graphical tools to do all this; but hey, it’s always good to try a new approach.

So I defined my model (yeah just one - let’s keep things simple first time round!) and it created the table for me.  Nice.

Inserting data, I discovered I’d forgotten to add a postcode field to the model.  No sweat, add one extra line to the model and… and what?  According to the Django documentation, the two options available are:

  1. Drop the table (and any existing data) or
  2. Alter the table structure by hand.

As I was only inserting the first record I went for option one.  However I wasn’t happy - the benefit of ‘not having to write SQL!’ does not stand up to scrutiny when it comes to modifying tables.  I’m lazy, and so dislike losing data (even when building a test application).  At the same time, changing the structure in the model AND going to change it in the DB doesn’t appeal either.  Hand-editing MySQL tables is asking for trouble ;)

With that out of the way, I was impressed by the ease of creation.  As I’ve commented in a feature request report a while back, Django’s admin isn’t as flexible as I’d like.  But for what I need for this site I think it will do it well.

Now to see if I can set up users with permission just to edit ONE record in this DB table - any way to tie their permissions to a record ID?