Skip to content

Commit 325cdd9

Browse files
committed
User get_user_model() rather than importing User directly
This is the recommended way to reference the user model according to the documentation[1]. It should be supported by at least Django 4, so can be assumed to work for NetBox releases older than 4.0 as well. I have only tested it with 4.0(.1) though. [1] https://docs.djangoproject.com/en/5.0/topics/auth/customizing/#referencing-the-user-model
1 parent b1f4673 commit 325cdd9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

vars/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ _netbox_storages_map:
1414
sftpstorage: []
1515

1616
netbox_superuser_script: |
17-
from django.contrib.auth.models import User
17+
from django.contrib.auth import get_user_model
1818
from base64 import b64decode
19+
User = get_user_model()
1920
password = b64decode("{{ netbox_superuser_password | b64encode }}").decode("UTF-8")
2021
query = User.objects.filter(username="{{ netbox_superuser_username }}")
2122
if not query.exists():
@@ -33,7 +34,8 @@ netbox_superuser_script: |
3334
3435
netbox_superuser_token: |
3536
from users.models import Token
36-
from django.contrib.auth.models import User
37+
from django.contrib.auth import get_user_model
38+
User = get_user_model()
3739
user = User.objects.get(username="{{ netbox_superuser_username }}")
3840
query = Token.objects.filter(user=user)
3941
if not query.exists():

0 commit comments

Comments
 (0)