Add connection type to NestedInterfaceSerializer

This commit is contained in:
Marco Ceppi 2019-11-26 10:57:03 -05:00
parent 62295c8b60
commit 40ddf9a12f
2 changed files with 4 additions and 3 deletions

View File

@ -1,6 +1,6 @@
from rest_framework import serializers
from dcim.constants import CONNECTION_STATUS_CHOICES
from dcim.constants import CONNECTION_STATUS_CHOICES, IFACE_TYPE_CHOICES
from dcim.models import (
Cable, ConsolePort, ConsoleServerPort, Device, DeviceBay, DeviceType, DeviceRole, FrontPort, FrontPortTemplate,
Interface, Manufacturer, Platform, PowerFeed, PowerOutlet, PowerPanel, PowerPort, Rack, RackGroup, RackRole,
@ -203,10 +203,11 @@ class NestedInterfaceSerializer(WritableNestedSerializer):
device = NestedDeviceSerializer(read_only=True)
url = serializers.HyperlinkedIdentityField(view_name='dcim-api:interface-detail')
connection_status = ChoiceField(choices=CONNECTION_STATUS_CHOICES, read_only=True)
type = ChoiceField(choices=IFACE_TYPE_CHOICES, required=False)
class Meta:
model = Interface
fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status']
fields = ['id', 'url', 'device', 'name', 'cable', 'connection_status', 'type']
class NestedRearPortSerializer(WritableNestedSerializer):

View File

@ -2449,7 +2449,7 @@ class InterfaceTest(APITestCase):
self.assertEqual(
sorted(response.data['results'][0]),
['cable', 'connection_status', 'device', 'id', 'name', 'url']
['cable', 'connection_status', 'device', 'id', 'name', 'type', 'url']
)
def test_create_interface(self):