Skip to content

Commit 40e8d1d

Browse files
helmetwearerpre-commit-ci[bot]ddabble
authored
Change admin.py to use Django's registered User Model (#1177)
* Update admin.py to use django's get_user_model Change the admin to properly integrate with custom user models * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Updated CHANGES.rst for #1177 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Anders <[email protected]>
1 parent e368d83 commit 40e8d1d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Unreleased
88
- Added feature to evaluate ``history`` model permissions explicitly when
99
``SIMPLE_HISTORY_ENFORCE_HISTORY_MODEL_PERMISSIONS`` is set to ``True``
1010
in ``settings`` (gh-1017).
11+
- Fixed ``SimpleHistoryAdmin`` not properly integrating with custom user models (gh-1177)
1112

1213
3.3.0 (2023-03-08)
1314
------------------

simple_history/admin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.contrib import admin
55
from django.contrib.admin import helpers
66
from django.contrib.admin.utils import unquote
7-
from django.contrib.auth import get_permission_codename
7+
from django.contrib.auth import get_permission_codename, get_user_model
88
from django.core.exceptions import PermissionDenied
99
from django.shortcuts import get_object_or_404, render
1010
from django.urls import re_path, reverse
@@ -15,8 +15,6 @@
1515

1616
from .utils import get_history_manager_for_model, get_history_model_for_model
1717

18-
USER_NATURAL_KEY = tuple(key.lower() for key in settings.AUTH_USER_MODEL.split(".", 1))
19-
2018
SIMPLE_HISTORY_EDIT = getattr(settings, "SIMPLE_HISTORY_EDIT", False)
2119

2220

@@ -72,9 +70,10 @@ def history_view(self, request, object_id, extra_context=None):
7270
for list_entry in action_list:
7371
setattr(list_entry, history_list_entry, value_for_entry(list_entry))
7472

75-
content_type = self.content_type_model_cls.objects.get_by_natural_key(
76-
*USER_NATURAL_KEY
73+
content_type = self.content_type_model_cls.objects.get_for_model(
74+
get_user_model()
7775
)
76+
7877
admin_user_view = "admin:{}_{}_change".format(
7978
content_type.app_label,
8079
content_type.model,

0 commit comments

Comments
 (0)