Merge django1.4 compatibility from Olivier.

(We need Django 1.5, so I'll hope this works.)