Skip to content

Commit

Permalink
feat (documentation): declutter the datamodel graph
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gythaogg committed Dec 18, 2024
1 parent 6f28df6 commit e2704da
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions apis_core/documentation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand Down

0 comments on commit e2704da

Please sign in to comment.