mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-22 11:38:45 -06:00
Closes: #17936 - GFK serializer field (#20706)
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CI / build (20.x, 3.13) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
Some checks failed
CI / build (20.x, 3.12) (push) Has been cancelled
CI / build (20.x, 3.13) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, python) (push) Has been cancelled
* Establish GFKSerializerField and replace get_* methods in circuits.py * Set read_only=True * Apply GFKSerializerField to all matching SerializerMethodFields * Use GFKSerializerField for ObjectChangeSerializer.changed_object and EventRuleSerializer.action_object
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from rest_framework import serializers
|
||||
|
||||
from ipam.api.serializers_.vrfs import RouteTargetSerializer
|
||||
from ipam.models import RouteTarget
|
||||
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
||||
from netbox.api.gfk_fields import GFKSerializerField
|
||||
from netbox.api.serializers import NetBoxModelSerializer, PrimaryModelSerializer
|
||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||
from utilities.api import get_serializer_for_model
|
||||
from vpn.choices import *
|
||||
from vpn.models import L2VPN, L2VPNTermination
|
||||
|
||||
@@ -53,7 +51,7 @@ class L2VPNTerminationSerializer(NetBoxModelSerializer):
|
||||
assigned_object_type = ContentTypeField(
|
||||
queryset=ContentType.objects.all()
|
||||
)
|
||||
assigned_object = serializers.SerializerMethodField(read_only=True)
|
||||
assigned_object = GFKSerializerField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = L2VPNTermination
|
||||
@@ -62,9 +60,3 @@ class L2VPNTerminationSerializer(NetBoxModelSerializer):
|
||||
'assigned_object', 'tags', 'custom_fields', 'created', 'last_updated'
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'l2vpn')
|
||||
|
||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||
def get_assigned_object(self, instance):
|
||||
serializer = get_serializer_for_model(instance.assigned_object)
|
||||
context = {'request': self.context['request']}
|
||||
return serializer(instance.assigned_object, nested=True, context=context).data
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from drf_spectacular.utils import extend_schema_field
|
||||
from rest_framework import serializers
|
||||
|
||||
from ipam.api.serializers_.ip import IPAddressSerializer
|
||||
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
||||
from netbox.api.gfk_fields import GFKSerializerField
|
||||
from netbox.api.serializers import NetBoxModelSerializer, OrganizationalModelSerializer, PrimaryModelSerializer
|
||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||
from utilities.api import get_serializer_for_model
|
||||
from vpn.choices import *
|
||||
from vpn.models import Tunnel, TunnelGroup, TunnelTermination
|
||||
from .crypto import IPSecProfileSerializer
|
||||
@@ -83,9 +81,7 @@ class TunnelTerminationSerializer(NetBoxModelSerializer):
|
||||
termination_type = ContentTypeField(
|
||||
queryset=ContentType.objects.all()
|
||||
)
|
||||
termination = serializers.SerializerMethodField(
|
||||
read_only=True
|
||||
)
|
||||
termination = GFKSerializerField(read_only=True)
|
||||
outside_ip = IPAddressSerializer(
|
||||
nested=True,
|
||||
required=False,
|
||||
@@ -99,11 +95,3 @@ class TunnelTerminationSerializer(NetBoxModelSerializer):
|
||||
'termination', 'outside_ip', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
)
|
||||
brief_fields = ('id', 'url', 'display')
|
||||
|
||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||
def get_termination(self, obj):
|
||||
if not obj.termination:
|
||||
return None
|
||||
serializer = get_serializer_for_model(obj.termination)
|
||||
context = {'request': self.context['request']}
|
||||
return serializer(obj.termination, nested=True, context=context).data
|
||||
|
||||
Reference in New Issue
Block a user