Changes between Version 10 and Version 11 of DjangoGraphviz
- Timestamp:
- Aug 6, 2006, 2:50:33 PM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DjangoGraphviz
v10 v11 33 33 Changelog 34 34 35 0.5 36 Cleaned up code, now the relationship arrows start from the 37 correct model attribute position 38 35 39 0.4 36 40 Fixed OneToOneField support (thanks, limodou) … … 49 53 50 54 __version__ = "0.4" 55 __svnid__ = "$Id: modelviz.py 4 2006-08-06 19:48:42Z verbosus $" 51 56 __license__ = "Python" 52 __author__ = "Antonio Cavedoni <http://cavedoni.com/ "57 __author__ = "Antonio Cavedoni <http://cavedoni.com/>" 53 58 __contributors__ = [ 54 59 "Stefano J. Attardi <http://attardi.org/>", … … 81 86 for o in get_models(app): 82 87 nodes = [] 83 nodes.append(""" %s [ 84 label = "{%s |""" % (o.__name__, o.__name__)) 88 nodes.append(""" subgraph cluster_%(model)s { 89 shape = "record"; 90 label = "%(model)s"; 91 fontname = "Helvetica Bold"; 92 fontsize = 10; 93 labelfontcolor = "black"; 94 %(model)s [label = "{""" % {'model': o.__name__}) 85 95 86 96 # model attributes 97 def add_attributes(): 98 nodes.append("<%(model)s_%(field)s>%(field)s : %(related)s|" % \ 99 {'model': o.__name__, 'field': field.name, 100 'related': type(field).__name__}) 101 87 102 for field in o._meta.fields: 88 nodes.append('%s : %s\\l' % (field.name, type(field).__name__))103 add_attributes() 89 104 90 105 if o._meta.many_to_many: 91 106 for field in o._meta.many_to_many: 92 nodes.append('%s : %s\\l' % (field.name, type(field).__name__))107 add_attributes() 93 108 94 nodes.append(""" }" \n]\n""")109 nodes.append(""" }"] [color="white" shape="record"];\n }\n""") 95 110 print "".join(nodes) 96 111 … … 98 113 rel = [] 99 114 100 for field in o._meta.fields: 101 if isinstance(field, ForeignKey): 102 _rel = ' %s -> %s [label="%s"];' % \ 103 (o.__name__, field.rel.to.__name__, type(field).__name__) 104 if _rel not in rel: 105 rel.append(_rel) 106 elif isinstance(field, OneToOneField): 107 _rel = ' %s -> %s [label="%s"] [arrowhead=none arrowtail=none];' % (o.__name__, field.rel.to.__name__, type(field).__name__) 108 if _rel not in rel: 109 rel.append(_rel) 115 def add_relation(extras=""): 116 _rel = """ %(model)s:%(model)s_%(field)s -> %(related)s 117 [label="%(relationship)s"] %(extras)s;""" % { 118 'model': o.__name__, 'field': field.name, 119 'related': field.rel.to.__name__, 120 'relationship': type(field).__name__, 121 'extras': extras} 122 if _rel not in rel: 123 rel.append(_rel) 110 124 111 125 for field in o._meta.fields: 112 126 if isinstance(field, ForeignKey): 113 _rel = ' %s -> %s [label="%s"];' % \ 114 (o.__name__, field.rel.to.__name__, type(field).__name__) 115 if _rel not in rel: 116 rel.append(_rel) 127 add_relation() 128 elif isinstance(field, OneToOneField): 129 add_relation("[arrowhead=none arrowtail=none]") 117 130 118 131 if o._meta.many_to_many: 119 132 for field in o._meta.many_to_many: 120 133 if isinstance(field, ManyToManyField): 121 _rel = ' %s -> %s [label="%s"] [arrowhead=normal arrowtail=normal];' % \ 122 (o.__name__, field.rel.to.__name__, type(field).__name__) 123 if _rel not in rel: 124 rel.append(_rel) 125 126 if isinstance(field, GenericRelation): 127 _rel = ' %s -> %s [label="%s"] [style="dotted"] [arrowhead=normal arrowtail=normal];' % \ 128 (o.__name__, field.rel.to.__name__, type(field).__name__) 129 if _rel not in rel: 130 rel.append(_rel) 134 add_relation("[arrowhead=normal arrowtail=normal]") 135 elif isinstance(field, GenericRelation): 136 add_relation( 137 '[style="dotted"] [arrowhead=normal arrowtail=normal]') 131 138 132 139 print "\n".join(rel)