title: Error while logging in when primary key of Django `User` is a `CharField`
body: <p>I wanted to use a <code>CharField</code> as primary key for Django <code>User</code> and add some extra fields to it. So, I extended <code>AbstractUser</code> model as given below:</p>
  
  <pre><code>class User(AbstractUser):
      id = models.CharField(primary_key=True, max_length=32, default=str(uuid.uuid4()).replace('-', ''))
      Telephone = models.CharField('Telephone', max_length=100, blank=True, null=True)
      Mobile = models.CharField('Mobile', max_length=100, blank=True, null=True)
  </code></pre>
  
  <p>This works perfectly for doing CRUD operations on User. But when I try to login as a User whose Superuser Status is <code>False</code>, following error shows up:</p>
  
  <pre><code>Environment:
  
  
  Request Method: GET
  Request URL: http://localhost:8000/admin/
  
  Django Version: 1.5.1
  Python Version: 2.7.3
  Installed Applications:
  ('django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.sites',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'django.contrib.admin',
   'django.contrib.humanize',
   'UserApp',)
  Installed Middleware:
  ('django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware')
  
  
  Traceback:
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in         get_response
    115.                         response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in wrapper
    219.                 return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
    91.                     response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
    89.         response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
    202.             return view(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
    89.         response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in index
    346.             has_module_perms = user.has_module_perms(app_label)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in has_module_perms
    367.         return _user_has_module_perms(self, app_label)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/models.py" in _user_has_module_perms
    288.             if backend.has_module_perms(user, app_label):
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in has_module_perms
    59.         for perm in self.get_all_permissions(user_obj):
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in get_all_permissions
    45.             user_obj._perm_cache.update(self.get_group_permissions(user_obj))
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/backends.py" in get_group_permissions
    35.                 perms = Permission.objects.filter(**{user_groups_query: user_obj})
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py" in filter
    155.         return self.get_query_set().filter(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in filter
    655.         return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in _filter_or_exclude
    673.             clone.query.add_q(Q(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in add_q
    1266.                             can_reuse=used_aliases, force_having=force_having)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/query.py" in add_filter
    1197.                 connector)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in add
    71.             value = obj.prepare(lookup_type, value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/where.py" in prepare
    339.             return self.field.get_prep_lookup(lookup_type, value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py" in get_prep_lookup
    143.             return self._pk_trace(value, 'get_prep_lookup', lookup_type)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.py" in _pk_trace
    216.         v = getattr(field, prep_func)(lookup_type, v, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_lookup
    322.             return self.get_prep_value(value)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py" in get_prep_value
    555.         return int(value)
  
  Exception Type: ValueError at /admin/
  Exception Value: invalid literal for int() with base 10: 'c4cadcd0538e45dcaee946d079e11be5'
  </code></pre>
  
  <p>I did some search a found that Django does a reverse many-to-many query to find out permissions when a non-superuser logs in. I checked working of reverse many-to-many query is case of when models has a <code>CharField</code> as primary key and found similar error. Please refer to this ticket <a href="https://code.djangoproject.com/ticket/21879" rel="nofollow">https://code.djangoproject.com/ticket/21879</a>. </p>
  
  <p>Is there a fix for this problem?</p>