djangoのモデルのfieldクラスの階層構造

from django.conf import settings
if not settings.configured:
    settings.configure()

import django.db.models as m

class Parser(object):
    def __init__(self):
        self.D = {}

    def eat(self, klass):
        D = self.D
        for k in reversed(klass.mro()):
            if k not in D:
                D[k] = {}
            D = D[k]

    def eats(self, seq):
        for cls in seq:
            self.eat(cls)
        
    def to_diag(self):
        def rec(D, i):
            for k, v in D.items():
                if v:
                    for vk in v.keys():
                        print "%s%s -> %s;" % (" "*i, k.__name__, vk.__name__)
                    rec(v, i+2)
        print "{"
        rec(self.D, 2)
        print "}"

p = Parser()
        
p.eats((v for k, v in m.__dict__.items() if k.endswith("Field")))
p.to_diag()