Changes between Version 10 and Version 11 of DjangoGraphviz


Ignore:
Timestamp:
08/06/2006 02:50:33 PM (9 years ago)
Author:
Antonio Cavedoni
Comment:

Code refactoring

Legend:

Unmodified
Added
Removed
Modified
  • DjangoGraphviz

    v10 v11  
    3333Changelog
    3434
     350.5
     36Cleaned up code, now the relationship arrows start from the
     37correct model attribute position
     38
    35390.4
    3640Fixed OneToOneField support (thanks, limodou)
     
    4953
    5054__version__ = "0.4"
     55__svnid__ = "$Id: modelviz.py 4 2006-08-06 19:48:42Z verbosus $"
    5156__license__ = "Python"
    52 __author__ = "Antonio Cavedoni <http://cavedoni.com/"
     57__author__ = "Antonio Cavedoni <http://cavedoni.com/>"
    5358__contributors__ = [
    5459   "Stefano J. Attardi <http://attardi.org/>",
     
    8186   for o in get_models(app):
    8287      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__})
    8595
    8696      # 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
    87102      for field in o._meta.fields:
    88          nodes.append('%s : %s\\l' % (field.name, type(field).__name__))
     103         add_attributes()
    89104         
    90105      if o._meta.many_to_many:
    91106         for field in o._meta.many_to_many:
    92             nodes.append('%s : %s\\l' % (field.name, type(field).__name__))
     107            add_attributes()
    93108
    94       nodes.append(""" }"\n]\n""")
     109      nodes.append(""" }"] [color="white" shape="record"];\n }\n""")
    95110      print "".join(nodes)
    96111
     
    98113      rel = []
    99114
    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)
    110124
    111125      for field in o._meta.fields:
    112126         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]")
    117130
    118131      if o._meta.many_to_many:
    119132         for field in o._meta.many_to_many:
    120133            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]')
    131138
    132139      print "\n".join(rel)
Back to Top