Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes: #14840 - Forces API to use django user model instead of proxy model #14881

Merged
merged 8 commits into from
Feb 5, 2024
7 changes: 7 additions & 0 deletions netbox/utilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def get_serializer_for_model(model, prefix=''):
# Serializers for Django's auth models are in the users app
if app_name == 'auth':
app_name = 'users'
# Account for changes using Proxy model
if app_name == 'users':
if model_name == 'NetBoxUser':
model_name = 'User'
elif model_name == 'NetBoxGroup':
model_name = 'Group'

serializer_name = f'{app_name}.api.serializers.{prefix}{model_name}Serializer'
try:
return dynamic_import(serializer_name)
Expand Down
2 changes: 2 additions & 0 deletions netbox/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def get_viewname(model, action=None, rest_api=False):
# Alter the app_label for group and user model_name to point to users app
if app_label == 'auth' and model_name in ['group', 'user']:
app_label = 'users'
if app_label == 'users' and model._meta.proxy and model_name in ['netboxuser', 'netboxgroup']:
model_name = model._meta.proxy_for_model._meta.model_name

viewname = f'{app_label}-api:{model_name}'
# Append the action, if any
Expand Down
Loading