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.

compat.py 1.3KB

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