Thanks Pedro Lima for the draft patch. Backport of 06f5da3d78 from master
06f5da3d78
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15009 bcc190cf-cafb-0310-a4f2-bffc1f526a37