|
|
@@ -1,10 +1,12 @@
|
|
|
from django.contrib.auth.models import ContentType
|
|
|
+from drf_yasg.utils import swagger_serializer_method
|
|
|
from rest_framework import serializers
|
|
|
|
|
|
from netbox.api import ChoiceField, ContentTypeField
|
|
|
from netbox.api.serializers import NestedGroupModelSerializer, PrimaryModelSerializer
|
|
|
from tenancy.choices import ContactPriorityChoices
|
|
|
from tenancy.models import *
|
|
|
+from utilities.api import get_serializer_for_model
|
|
|
from .nested_serializers import *
|
|
|
|
|
|
|
|
|
@@ -92,6 +94,7 @@ class ContactAssignmentSerializer(PrimaryModelSerializer):
|
|
|
content_type = ContentTypeField(
|
|
|
queryset=ContentType.objects.all()
|
|
|
)
|
|
|
+ object = serializers.SerializerMethodField(read_only=True)
|
|
|
contact = NestedContactSerializer()
|
|
|
role = NestedContactRoleSerializer(required=False, allow_null=True)
|
|
|
priority = ChoiceField(choices=ContactPriorityChoices, required=False)
|
|
|
@@ -99,6 +102,12 @@ class ContactAssignmentSerializer(PrimaryModelSerializer):
|
|
|
class Meta:
|
|
|
model = ContactAssignment
|
|
|
fields = [
|
|
|
- 'id', 'url', 'display', 'content_type', 'object_id', 'contact', 'role', 'priority', 'created',
|
|
|
+ 'id', 'url', 'display', 'content_type', 'object_id', 'object', 'contact', 'role', 'priority', 'created',
|
|
|
'last_updated',
|
|
|
]
|
|
|
+
|
|
|
+ @swagger_serializer_method(serializer_or_field=serializers.DictField)
|
|
|
+ def get_object(self, instance):
|
|
|
+ serializer = get_serializer_for_model(instance.content_type.model_class(), prefix='Nested')
|
|
|
+ context = {'request': self.context['request']}
|
|
|
+ return serializer(instance.object, context=context).data
|