Hi,
for anyone who is interested - here's a script I coded in a couple of
mins to generate a relationship diagram code out of any elixir
model.py module, using graphviz ( http://www.graphviz.org/ ). The
output of this script must be compiled with graphviz to generate the
pretty pictures. Rename model with your own Elixir model definition
python module.
import elixir, model, inspect
from model import *
classes = [m for m in model.__dict__.values() if inspect.isclass(m)
and issubclass(m, Entity) ]
print('digraph G {')
for c in classes:
manytoones = [f for f in c.__dict__.values() if f.__class__ ==
elixir.relationships.ManyToOne]
onetomanys = [f for f in c.__dict__.values() if f.__class__ ==
elixir.relationships.OneToMany]
onetoones = [f for f in c.__dict__.values() if f.__class__ ==
elixir.relationships.OneToOne]
manytomanys = [f for f in c.__dict__.values() if f.__class__ ==
elixir.relationships.ManyToMany]
for c2 in manytoones:
print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'%
(c.__name__, c2.of_kind, '1', '*', c2.name))
for c2 in onetomanys:
print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'%
(c.__name__, c2.of_kind, '*', '1', c2.name))
for c2 in onetoones:
print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'%
(c.__name__, c2.of_kind, '1', '1', c2.name))
for c2 in manytomanys:
print('%s -> %s [headlabel="%s" taillabel="%s" label="%s"]'%
(c.__name__, c2.of_kind, '*', '*', c2.name))
print('}')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---