From 2c9ae60dec31732d5db77ad585eb662580c126b4 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 6 Oct 2020 16:34:03 -0400 Subject: [PATCH] Optimize path node representations --- netbox/dcim/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/netbox/dcim/utils.py b/netbox/dcim/utils.py index d36cb1ad3..ccc849aa5 100644 --- a/netbox/dcim/utils.py +++ b/netbox/dcim/utils.py @@ -5,12 +5,20 @@ from .exceptions import CableTraceSplit def object_to_path_node(obj): - return f'{obj._meta.model_name}:{obj.pk}' + """ + Return a representation of an object suitable for inclusion in a CablePath path. Node representation is in the + form :. + """ + ct = ContentType.objects.get_for_model(obj) + return f'{ct.pk}:{obj.pk}' def path_node_to_object(repr): - model_name, object_id = repr.split(':') - model_class = ContentType.objects.get(model=model_name).model_class() + """ + Given a path node representation, return the corresponding object. + """ + ct_id, object_id = repr.split(':') + model_class = ContentType.objects.get(pk=ct_id).model_class() return model_class.objects.get(pk=int(object_id))