@@ -39,20 +39,34 @@ class CustomObjectLink(PluginTemplateExtension):
39
39
40
40
def left_page (self ):
41
41
# 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
+ )
44
48
linked_custom_objects = []
45
49
for field in custom_object_type_fields :
46
50
model = field .custom_object_type .get_model ()
47
51
for model_object in model .objects .all ():
48
52
model_field = getattr (model_object , field .name )
49
- if field .type == CustomFieldTypeChoices .TYPE_MULTIOBJECT :
50
- if model_field .filter (id = self .context ["object" ].pk ).exists ():
51
- linked_custom_objects .append (LinkedCustomObject (custom_object = model_object , field = field ))
52
- else :
53
- if model_field .id == self .context ["object" ].pk :
54
- linked_custom_objects .append (LinkedCustomObject (custom_object = model_object , field = field ))
55
- return render_jinja2 ("""
53
+ if model_field :
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
+ """
56
70
<div class="card">
57
71
<h2 class="card-header">Custom Objects linking to this object</h2>
58
72
<table class="table table-hover attr-table">
@@ -72,7 +86,9 @@ def left_page(self):
72
86
{% endfor %}
73
87
</table>
74
88
</div>
75
- """ , {'linked_custom_objects' : linked_custom_objects })
89
+ """ ,
90
+ {"linked_custom_objects" : linked_custom_objects },
91
+ )
76
92
77
93
78
94
template_extensions = (
0 commit comments