mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
12794 change User ref to get_user_model (#12905)
* 12794 change User ref to get_user_model * 12794 call get_user_model once in tests * 12794 call get_user_model once in tests * 12794 use settings.AUTH_USER_MODEL for FK reference
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
@@ -28,7 +29,7 @@ class NestedUserSerializer(WritableNestedSerializer):
|
||||
url = serializers.HyperlinkedIdentityField(view_name='users-api:user-detail')
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
model = get_user_model()
|
||||
fields = ['id', 'url', 'display', 'username']
|
||||
|
||||
@extend_schema_field(OpenApiTypes.STR)
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
@@ -30,7 +31,7 @@ class UserSerializer(ValidatedModelSerializer):
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
model = get_user_model()
|
||||
fields = (
|
||||
'id', 'url', 'display', 'username', 'password', 'first_name', 'last_name', 'email', 'is_staff', 'is_active',
|
||||
'date_joined', 'groups',
|
||||
@@ -124,7 +125,7 @@ class ObjectPermissionSerializer(ValidatedModelSerializer):
|
||||
many=True
|
||||
)
|
||||
users = SerializedPKRelatedField(
|
||||
queryset=User.objects.all(),
|
||||
queryset=get_user_model().objects.all(),
|
||||
serializer=NestedUserSerializer,
|
||||
required=False,
|
||||
many=True
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from django.db.models import Count
|
||||
from drf_spectacular.utils import extend_schema
|
||||
from drf_spectacular.types import OpenApiTypes
|
||||
@@ -32,7 +33,7 @@ class UsersRootView(APIRootView):
|
||||
#
|
||||
|
||||
class UserViewSet(NetBoxModelViewSet):
|
||||
queryset = RestrictedQuerySet(model=User).prefetch_related('groups').order_by('username')
|
||||
queryset = RestrictedQuerySet(model=get_user_model()).prefetch_related('groups').order_by('username')
|
||||
serializer_class = serializers.UserSerializer
|
||||
filterset_class = filtersets.UserFilterSet
|
||||
|
||||
|
Reference in New Issue
Block a user