1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#12795: Introduce a custom Group model (#15304)

* Rename sequences & indexes after renaming users table

* Migrate from auth.Group to a custom group model

* Delete original groups from auth_group table

* Update object & multi-object custom fields referencing the Group model

* Fix ContentType resolution

* Clean up obsolete logic for view/serializer resolution
This commit is contained in:
Jeremy Stretch
2024-03-04 08:29:53 -05:00
committed by GitHub
parent 709eac6b98
commit c6a3fc2407
26 changed files with 208 additions and 119 deletions

View File

@@ -31,23 +31,13 @@ def get_serializer_for_model(model, prefix=''):
"""
Dynamically resolve and return the appropriate serializer for a model.
"""
app_name, model_name = model._meta.label.split('.')
# 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'
app_label, model_name = model._meta.label.split('.')
serializer_name = f'{app_label}.api.serializers.{prefix}{model_name}Serializer'
try:
return dynamic_import(serializer_name)
except AttributeError:
raise SerializerNotFound(
f"Could not determine serializer for {app_name}.{model_name} with prefix '{prefix}'"
f"Could not determine serializer for {app_label}.{model_name} with prefix '{prefix}'"
)