Search code examples
pythondjangodjango-modelsmodeling

How can I draw diagrams from database in python


How can I visually model items in a database using python?

I have a Django project that currently models my home network in the admin views. It currently describes what devices there are and what they are connected to. For example:

Devices:
    Computer1
    Computer2
    Laptop1
    Mobile1
    Router1
    ROuter2

ConnectionTypes:
    Wireless24ghz
    Wireless5ghz
    cat5
    cat5e
    cat6

Connections:
    host1:
        src:Computer1
        dst:Router1
        con_type:cat5e
    trunk1:
        src:Router1
        dst:Router2
        con_type:cat6
    host2:
        src:Mobile1
        dst:Router1
        con_type:Wireless24ghz

The database is a bit more complex than this, however I'm keeping it simple for now as it's not that important.

What I am wondering is, how I can graphically model my network using python code to look at the database tables? By graphically model I mean something similar to a Visio diagram in that I can see it and (not necessary but a HUGE bonus) interact with it, either via webpage or application.

Are there any existing python libraries that provide this sort of functionality? I understand JavaScript is good for this kind of modelling but I'm completely unsure of how I would go about doing it.

It's worth noting I'm not after anything fancy, simply drawing devices as rectangles and connections as lines going between rectangles is good enough.


Solution

  • I am pretty sure there is no ready solution for this. Look at the graphviz library and make a management command to create a DOT graph. Here is a graphviz tutorial article http://matthiaseisen.com/articles/graphviz/