Skip to content

Commit 7cec7da

Browse files
committed
Removed 'get_user_model' usage in admin.py on import
1 parent 703e985 commit 7cec7da

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

runtests.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@
1313
media_root = join(abspath(dirname(__file__)), 'test_files')
1414
rmtree(media_root, ignore_errors=True)
1515

16-
installed_apps = (
16+
installed_apps = [
1717
'django.contrib.contenttypes',
1818
'django.contrib.auth',
1919
'django.contrib.sessions',
2020
'django.contrib.admin',
2121
'simple_history',
2222
'simple_history.tests',
2323
'simple_history.tests.external',
24-
)
25-
auth_user_model = 'auth.User'
26-
if django.VERSION >= (1, 5):
27-
installed_apps += ('simple_history.tests.custom_user', )
28-
auth_user_model = 'custom_user.CustomUser'
24+
]
2925

3026
DEFAULT_SETTINGS = dict(
3127
ROOT_URLCONF='simple_history.tests.urls',
@@ -37,14 +33,16 @@
3733
'ENGINE': 'django.db.backends.sqlite3',
3834
}
3935
},
40-
AUTH_USER_MODEL=auth_user_model,
4136
MIDDLEWARE_CLASSES=[
4237
'django.contrib.sessions.middleware.SessionMiddleware',
4338
'django.contrib.auth.middleware.AuthenticationMiddleware',
4439
'django.contrib.messages.middleware.MessageMiddleware',
4540
],
4641
)
4742

43+
if django.VERSION >= (1, 5):
44+
installed_apps.append('simple_history.tests.custom_user')
45+
DEFAULT_SETTINGS['AUTH_USER_MODEL'] = 'custom_user.CustomUser'
4846

4947
def main():
5048
if not settings.configured:

simple_history/admin.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
from django.utils.encoding import force_text
2020
except ImportError: # django 1.3 compatibility
2121
from django.utils.encoding import force_unicode as force_text
22+
from django.conf import settings
2223

2324
try:
24-
from django.contrib.auth import get_user_model
25-
User = get_user_model()
26-
except ImportError: # django 1.4 compatibility
27-
from django.contrib.auth.models import User
25+
USER_NATURAL_KEY = settings.AUTH_USER_MODEL
26+
except AttributeError:
27+
USER_NATURAL_KEY = "auth.User"
28+
USER_NATURAL_KEY = tuple(key.lower() for key in USER_NATURAL_KEY.split('.', 1))
2829

2930

3031
class SimpleHistoryAdmin(admin.ModelAdmin):
@@ -59,7 +60,8 @@ def history_view(self, request, object_id, extra_context=None):
5960
action_list = history.filter(**{pk_name: object_id})
6061
# If no history was found, see whether this object even exists.
6162
obj = get_object_or_404(model, pk=object_id)
62-
content_type = ContentType.objects.get_for_model(User)
63+
content_type = ContentType.objects.get_by_natural_key(
64+
*USER_NATURAL_KEY)
6365
admin_user_view = 'admin:%s_%s_change' % (content_type.app_label,
6466
content_type.model)
6567
context = {

0 commit comments

Comments
 (0)