mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-30 12:26:25 -06:00
Simplify serializer and add ip_addresses
This commit is contained in:
parent
e2e5af5303
commit
17a2b53521
@ -10,6 +10,7 @@ from dcim.models import (
|
|||||||
)
|
)
|
||||||
from ipam.api.serializers_.vlans import VLANSerializer, VLANTranslationPolicySerializer
|
from ipam.api.serializers_.vlans import VLANSerializer, VLANTranslationPolicySerializer
|
||||||
from ipam.api.serializers_.vrfs import VRFSerializer
|
from ipam.api.serializers_.vrfs import VRFSerializer
|
||||||
|
from ipam.api.serializers_.ip import IPAddressSerializer
|
||||||
from ipam.models import VLAN
|
from ipam.models import VLAN
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
|
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
|
||||||
@ -211,13 +212,11 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
|
|||||||
count_ipaddresses = serializers.IntegerField(read_only=True)
|
count_ipaddresses = serializers.IntegerField(read_only=True)
|
||||||
count_fhrp_groups = serializers.IntegerField(read_only=True)
|
count_fhrp_groups = serializers.IntegerField(read_only=True)
|
||||||
mac_address = serializers.CharField(
|
mac_address = serializers.CharField(
|
||||||
required=False,
|
|
||||||
default=None,
|
|
||||||
allow_blank=True,
|
|
||||||
allow_null=True,
|
allow_null=True,
|
||||||
read_only=True
|
read_only=True
|
||||||
)
|
)
|
||||||
mac_addresses = MACAddressSerializer(many=True, read_only=True)
|
mac_addresses = MACAddressSerializer(many=True, nested=True, read_only=True, allow_null=True)
|
||||||
|
ip_addresses = IPAddressSerializer(many=True, nested=True, read_only=True, allow_null=True)
|
||||||
wwn = serializers.CharField(required=False, default=None, allow_blank=True, allow_null=True)
|
wwn = serializers.CharField(required=False, default=None, allow_blank=True, allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -230,7 +229,7 @@ class InterfaceSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
|
|||||||
'cable', 'cable_end', 'wireless_link', 'link_peers', 'link_peers_type', 'wireless_lans', 'vrf',
|
'cable', 'cable_end', 'wireless_link', 'link_peers', 'link_peers_type', 'wireless_lans', 'vrf',
|
||||||
'l2vpn_termination', 'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable',
|
'l2vpn_termination', 'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable',
|
||||||
'tags', 'custom_fields', 'created', 'last_updated', 'count_ipaddresses', 'count_fhrp_groups', '_occupied',
|
'tags', 'custom_fields', 'created', 'last_updated', 'count_ipaddresses', 'count_fhrp_groups', '_occupied',
|
||||||
'mac_addresses',
|
'mac_addresses', 'ip_addresses',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
|
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', 'cable', '_occupied')
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ class BaseInterface(models.Model):
|
|||||||
def count_fhrp_groups(self):
|
def count_fhrp_groups(self):
|
||||||
return self.fhrp_group_assignments.count()
|
return self.fhrp_group_assignments.count()
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def mac_address(self):
|
def mac_address(self):
|
||||||
if macaddress := self.mac_addresses.order_by('-is_primary').first():
|
if macaddress := self.mac_addresses.order_by('-is_primary').first():
|
||||||
return macaddress.mac_address
|
return macaddress.mac_address
|
||||||
|
Loading…
Reference in New Issue
Block a user