applied patches from https://code.djangoproject.com/attachment/ticket/16778