mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-19 17:59:11 -06:00
Added parent_device to DeviceSerializer
This commit is contained in:
parent
97fbfeecc3
commit
80c8d2f0c0
@ -221,11 +221,26 @@ class DeviceSerializer(serializers.ModelSerializer):
|
|||||||
platform = PlatformNestedSerializer()
|
platform = PlatformNestedSerializer()
|
||||||
rack = RackNestedSerializer()
|
rack = RackNestedSerializer()
|
||||||
primary_ip = DeviceIPAddressNestedSerializer()
|
primary_ip = DeviceIPAddressNestedSerializer()
|
||||||
|
parent_device = serializers.SerializerMethodField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Device
|
model = Device
|
||||||
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'platform', 'serial', 'rack', 'position',
|
fields = ['id', 'name', 'display_name', 'device_type', 'device_role', 'platform', 'serial', 'rack', 'position',
|
||||||
'face', 'status', 'primary_ip', 'comments']
|
'face', 'parent_device', 'status', 'primary_ip', 'comments']
|
||||||
|
|
||||||
|
def get_parent_device(self, obj):
|
||||||
|
try:
|
||||||
|
device_bay = obj.parent_bay
|
||||||
|
except DeviceBay.DoesNotExist:
|
||||||
|
return None
|
||||||
|
return {
|
||||||
|
'id': device_bay.device.pk,
|
||||||
|
'name': device_bay.device.name,
|
||||||
|
'device_bay': {
|
||||||
|
'id': device_bay.pk,
|
||||||
|
'name': device_bay.name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DeviceNestedSerializer(serializers.ModelSerializer):
|
class DeviceNestedSerializer(serializers.ModelSerializer):
|
||||||
|
Loading…
Reference in New Issue
Block a user