Fix django crash found by Alexander Cherepanov