Most of the credit for this large patch goes to Anssi Kääriäinen. Many thanks to all the people who contributed to the discussion.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16284 bcc190cf-cafb-0310-a4f2-bffc1f526a37