Fixes for Python 3/Django 1.5

This fixes an issue which comes up under django versions more recent than django/django@c5ef65bcf324f4c90b53be90f4aec069a68e8c59.