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

Added API serializer for ObjectChange

This commit is contained in:
Jeremy Stretch
2018-06-19 14:57:03 -04:00
parent 38569029d8
commit 23f91274d6
5 changed files with 85 additions and 6 deletions

View File

@ -16,6 +16,8 @@ from rest_framework.response import Response
from rest_framework.serializers import Field, ModelSerializer, RelatedField, ValidationError
from rest_framework.viewsets import GenericViewSet, ViewSet
from .utils import dynamic_import
WRITE_OPERATIONS = ['create', 'update', 'partial_update', 'delete']
@ -24,6 +26,20 @@ class ServiceUnavailable(APIException):
default_detail = "Service temporarily unavailable, please try again later."
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('.')
serializer_name = '{}.api.serializers.{}{}Serializer'.format(
app_name, prefix, model_name
)
try:
return dynamic_import(serializer_name)
except ImportError:
return None
#
# Authentication
#