mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 01:48:38 -06:00
Closes #2034: Include the ID when showing nested interface connections
This commit is contained in:
parent
63100b683d
commit
b0985ebd42
@ -609,10 +609,11 @@ class InterfaceSerializer(ValidatedModelSerializer):
|
|||||||
|
|
||||||
def get_interface_connection(self, obj):
|
def get_interface_connection(self, obj):
|
||||||
if obj.connection:
|
if obj.connection:
|
||||||
return OrderedDict((
|
context = {
|
||||||
('interface', NestedInterfaceSerializer(obj.connected_interface, context=self.context).data),
|
'request': self.context['request'],
|
||||||
('status', obj.connection.connection_status),
|
'interface': obj.connected_interface,
|
||||||
))
|
}
|
||||||
|
return ContextualInterfaceConnectionSerializer(obj.connection, context=context).data
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@ -677,6 +678,21 @@ class NestedInterfaceConnectionSerializer(WritableNestedSerializer):
|
|||||||
fields = ['id', 'url', 'connection_status']
|
fields = ['id', 'url', 'connection_status']
|
||||||
|
|
||||||
|
|
||||||
|
class ContextualInterfaceConnectionSerializer(serializers.ModelSerializer):
|
||||||
|
"""
|
||||||
|
A read-only representation of an InterfaceConnection from the perspective of either of its two connected Interfaces.
|
||||||
|
"""
|
||||||
|
interface = serializers.SerializerMethodField(read_only=True)
|
||||||
|
connection_status = ChoiceFieldSerializer(choices=CONNECTION_STATUS_CHOICES, read_only=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = InterfaceConnection
|
||||||
|
fields = ['id', 'interface', 'connection_status']
|
||||||
|
|
||||||
|
def get_interface(self, obj):
|
||||||
|
return NestedInterfaceSerializer(self.context['interface'], context=self.context).data
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Virtual chassis
|
# Virtual chassis
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user