You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536
  1. from django.conf import settings
  2. from django.contrib.auth.models import User
  3. def get_user_model():
  4. """
  5. Return the User model
  6. Using this function instead of Django 1.5's get_user_model allows backwards
  7. compatibility with Django 1.4.
  8. """
  9. try:
  10. # Django 1.5+
  11. from django.contrib.auth import get_user_model
  12. except ImportError:
  13. # Django <= 1.4
  14. model = User
  15. else:
  16. model = get_user_model()
  17. # Test if user model has any custom fields and add attributes to the _meta
  18. # class
  19. core_fields = set([f.name for f in User._meta.fields])
  20. model_fields = set([f.name for f in model._meta.fields])
  21. new_fields = model_fields.difference(core_fields)
  22. model._meta.has_additional_fields = len(new_fields) > 0
  23. model._meta.additional_fields = new_fields
  24. return model
  25. # A setting that can be used in foreign key declarations
  26. AUTH_USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
  27. # Two additional settings that are useful in South migrations when
  28. # specifying the user model in the FakeORM
  29. AUTH_USER_APP_LABEL, AUTH_USER_MODEL_NAME = AUTH_USER_MODEL.split('.')