@@ -39,20 +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 )
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+ """
5670 <div class="card">
5771 <h2 class="card-header">Custom Objects linking to this object</h2>
5872 <table class="table table-hover attr-table">
@@ -72,7 +86,9 @@ def left_page(self):
7286 {% endfor %}
7387 </table>
7488 </div>
75- """ , {'linked_custom_objects' : linked_custom_objects })
89+ """ ,
90+ {"linked_custom_objects" : linked_custom_objects },
91+ )
7692
7793
7894template_extensions = (
0 commit comments