Skip to content

Commit 9c77792

Browse files
committed
NPL-415 fix detail page when custom object links is null
1 parent 2e26e72 commit 9c77792

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

netbox_custom_objects/template_content.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,34 @@ class CustomObjectLink(PluginTemplateExtension):
3939

4040
def left_page(self):
4141
# TODO: Improve performance of these nested queries
42-
content_type = ContentType.objects.get_for_model(self.context['object']._meta.model)
43-
custom_object_type_fields = CustomObjectTypeField.objects.filter(related_object_type=content_type)
42+
content_type = ContentType.objects.get_for_model(
43+
self.context["object"]._meta.model
44+
)
45+
custom_object_type_fields = CustomObjectTypeField.objects.filter(
46+
related_object_type=content_type
47+
)
4448
linked_custom_objects = []
4549
for field in custom_object_type_fields:
4650
model = field.custom_object_type.get_model()
4751
for model_object in model.objects.all():
4852
model_field = getattr(model_object, field.name)
4953
if model_field:
50-
if field.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
51-
if model_field.filter(id=self.context["object"].pk).exists():
52-
linked_custom_objects.append(LinkedCustomObject(custom_object=model_object, field=field))
53-
else:
54-
if model_field.id == self.context["object"].pk:
55-
linked_custom_objects.append(LinkedCustomObject(custom_object=model_object, field=field))
56-
return render_jinja2("""
54+
if field.type == CustomFieldTypeChoices.TYPE_MULTIOBJECT:
55+
if model_field.filter(id=self.context["object"].pk).exists():
56+
linked_custom_objects.append(
57+
LinkedCustomObject(
58+
custom_object=model_object, field=field
59+
)
60+
)
61+
else:
62+
if model_field.id == self.context["object"].pk:
63+
linked_custom_objects.append(
64+
LinkedCustomObject(
65+
custom_object=model_object, field=field
66+
)
67+
)
68+
return render_jinja2(
69+
"""
5770
<div class="card">
5871
<h2 class="card-header">Custom Objects linking to this object</h2>
5972
<table class="table table-hover attr-table">
@@ -73,7 +86,9 @@ def left_page(self):
7386
{% endfor %}
7487
</table>
7588
</div>
76-
""", {'linked_custom_objects': linked_custom_objects})
89+
""",
90+
{"linked_custom_objects": linked_custom_objects},
91+
)
7792

7893

7994
template_extensions = (

0 commit comments

Comments
 (0)