Commits

Peter Sagerson committed a3adaab

Documentation for get_user_model.

  • Participants
  • Parent commits d29f517
  • Branches usermodel

Comments (0)

Files changed (3)

django_auth_ldap/backend.py

 import pprint
 import copy
 
-import django.db
 from django.contrib.auth.models import User, Group, Permission, SiteProfileNotAvailable
 from django.core.cache import cache
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
     from django.contrib.auth import get_user_model
     get_user_username = lambda u: u.get_username()
 except ImportError:
-    get_user_model = lambda: User
+    get_user_model = lambda: User                                        # noqa
     get_user_username = lambda u: u.username
 
 
     ldap = property(_get_ldap)
 
     def get_user_model(self):
+        """
+        By default, this will return the model class configured by
+        AUTH_USER_MODEL. Subclasses may wish to override it and return a proxy
+        model.
+        """
         return get_user_model()
 
     #

docs/source/reference.rst

         the indicated Django user as if they had just logged in.
         :setting:`AUTH_LDAP_ALWAYS_UPDATE_USER` is ignored (assumed ``True``).
 
+    .. method:: get_user_model(self)
+
+        Returns the user model that
+        :meth:`~django_auth_ldap.backend.LDAPBackend.get_or_create_user` will
+        instantiate. In Django 1.5, custom user models will be respected; in
+        earlier versions, the model defaults to
+        :class:`django.contrib.auth.models.User`. Subclasses would most likely
+        override this in order to substitute a :ref:`proxy model
+        <proxy-models>`.
+
     .. method:: get_or_create_user(self, username, ldap_user)
 
         Given a username and an LDAP user object, this must return a valid
 
         The default implementation calls ``<model>.objects.get_or_create()``,
         using a case-insensitive query and creating new users with lowercase
-        usernames. In Django 1.5, custom user models will be respected; in
-        earlier versions, the model is always
-        :class:`django.contrib.auth.models.User`. Subclasses are welcome to
-        associate LDAP users to Django users any way they like.
+        usernames. The user model is obtained from
+        :meth:`~django_auth_ldap.backend.LDAPBackend.get_user_model`. A subclass
+        may override this to associate LDAP users to Django users any way it
+        likes.
 
     .. method:: ldap_to_django_username(username)
 

docs/source/users.rst

 case-insensitive, the default implementation also searches for existing Django
 users with an iexact query and new users are created with lowercase usernames.
 See :meth:`~django_auth_ldap.backend.LDAPBackend.get_or_create_user` if you'd
-like to override this behavior.
+like to override this behavior. See
+:meth:`~django_auth_ldap.backend.LDAPBackend.get_user_model` if you'd like to
+substitute a proxy model.
 
 .. note::