How-To

2009


Testing Django Views for Concurrency Issues (Updated for Django 4.2 in 2024)

Editor's note: This post was originally published in May, 2009 and was updated in December, 2024 to incorporate changes in Django and improvements suggested by our readers. It has also been tested for compatibility as of the Django 4.2 release.

Explicit Table Locking with PostgreSQL and Django

By default, Django doesn't do explicit table locking. This is OK for most read-heavy scenarios, but sometimes you need guaranteed, exclusive access to the data. Caktus uses PostgreSQL in most of our production environments, so we can use the various lock modes it provides to control concurrent access to the data. Once we obtain a lock in PostgreSQL, it is held for the remainder of the current transaction. Django provides transaction management, so all we need to do is execute a SQL LOCK statement within a transaction, and Django and PostgreSQL will handle the rest.

Parsing Microseconds in a Django Form

There's currently no way to accept microsecond-precision input through a Django form's DateTimeField. This is an acknowledged bug, but the official solution might not come very soon, because the real fix is non-trivial.

Seamlessly switch off (and on) a Django (or other WSGI) site for upgrades

In preparation for migrating the EveryWatt database from one machine to another, I wrote this little WSGI script to easily disable the site while I copy the data. Since it doesn't depend on Django or really anything else (other than a functioning WSGI server), you can use it for other upgrades, too.

Eclipse Ganymede and Subclipse on Ubuntu - JavaHL (JNI) not available

I finally got around to updating my Eclipse, PyDev, and Subclipse environment today, which I use for Django development.

Formerly I was using the SvnKit (pure-Java) libraries. SvnKit "felt" slow to me, compared to my command line SVN client, so this time I tried to get the JavaHL (JNI) libraries working.

Downsizing an LVM/RAID root partition

At Caktus we use LVM2 on a RAID1 device to ease disk management on a number of our servers. Recently I needed to downsize the root partition of one of the servers, so I rebooted onto an Ubuntu 8.10 LiveCD and attempted to load the RAID/LVM info.

Migrating from django-photologue 1.x to 2.x

We're in the process of updating a web app for a client that was built last year about this time using Django and Photologue. Needless to say, there have been a lot of changes to both over the past year!

Solving NFS issues on embedded machines

As part of my work on EveryWatt, I setup an NFS-based development environment for one of the data loggers we use for energy monitoring in the Caktus office. The stock 2.4 Linux kernel in the machine seemed to have some trouble mounting the file system root I had exported from one of our servers. The symptoms included long delays for most if not all activities that used the file system and lots of messages like these in dmesg:

Overriding Django admin templates for fun and profit

Alex Lemann

Motivation & Goal

I sometimes find the admin interface's lists of instances of models overwhelming. The filters and searching helps, but it would be nice to get an overview of the data that is being shown. Particularly I wanted to generate a graph based on the filters selected by the user, so that only items displayed after a filter would be graphed.

2008


Entering Contacts in CiviCRM

One of our non-profit clients recently asked for help entering the numerous business cards they get at trade shows, etc., into their Customer Relationship Management database, a copy of CiviCRM that we setup and manage for them. The best path for entering contacts isn't necessarily obvious from the get-go, but the following procedure is the best we've found and has the lowest up-front investment (you might be able to do something more efficient with a Profile, but that doesn't seem as flexible with respect to matching existing contacts).