From 7730668be062905e4c7dc3469eed3c142a4c6c79 Mon Sep 17 00:00:00 2001 From: Gytha Ogg Date: Tue, 17 Dec 2024 15:33:12 +0100 Subject: [PATCH] feat(documentation): declutter the datamodel graph - show only one edge between a subject model and an object model - show reverse name of the relations in the edge label if it is different from the name - slightly reduce the size of the label on the edge --- apis_core/documentation/utils.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/apis_core/documentation/utils.py b/apis_core/documentation/utils.py index 3c0b50d49..6602fd225 100644 --- a/apis_core/documentation/utils.py +++ b/apis_core/documentation/utils.py @@ -36,12 +36,29 @@ def edges(self): for rel in self.relations: for subj_class in rel.model_class().subj_list(): + subj_name = ContentType.objects.get_for_model(subj_class).name for obj_class in rel.model_class().obj_list(): - key = ( - ContentType.objects.get_for_model(subj_class).name, - ContentType.objects.get_for_model(obj_class).name, - ) - edges[key].append(force_str(rel.model_class().name())) + obj_name = ContentType.objects.get_for_model(obj_class).name + + original_pair = (subj_name, obj_name) + key = tuple(sorted(original_pair)) + + rel_model = rel.model_class() + rel_label = "" + if key == original_pair: + rel_label = ( + f"{force_str(rel_model.name())}/{force_str(rel_model.reverse_name())}" + if rel_model.name() != rel_model.reverse_name() + else rel_model.name() + ) + else: + rel_label = ( + f"{force_str(rel_model.reverse_name())}/{force_str(rel_model.name())}" + if rel_model.name() != rel_model.reverse_name() + else rel_model.name() + ) + + edges[key].append(rel_label) return edges def make_graph(self): @@ -61,7 +78,7 @@ def make_graph(self): node.set_style("filled") graph.add_node(node) for (subj, obj), names in self.edges().items(): - e = Edge(subj, obj, label="\n".join(names)) + e = Edge(subj, obj, label="\n".join(names), fontsize="11") graph.add_edge(e) self.graph = {"svg": graph.create_svg().decode(), "dot": graph.to_string()} except ImportError as e: