如何在python中从数据库中绘制图表

时间:2015-10-23 20:37:30

标签: python django django-models modeling

如何使用python在数据库中对项目进行可视化建模?

我有一个Django项目,目前在管理视图中为我的家庭网络建模。它目前描述了有哪些设备以及它们连接的内容。例如:

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

数据库比这更复杂,但是我现在保持简单,因为它并不重要。

我想知道的是,我如何使用python代码以图形方式模拟我的网络来查看数据库表?通过图形模型,我的意思是类似于Visio图表,我可以通过网页或应用程序看到它并且(不是必需的,但是巨大的奖励)与它进行交互。

是否有任何现有的python库提供这种功能?我理解JavaScript对于这种建模很有用,但我完全不确定我将如何去做。

值得注意的是,我没有追求任何花哨的东西,只是将设备绘制为矩形和连接,因为矩形之间的线条足够好。

4 个答案:

答案 0 :(得分:3)

我很确定没有现成的解决方案。查看graphviz库并创建管理命令以创建DOT图。这是graphviz教程文章http://matthiaseisen.com/articles/graphviz/

答案 1 :(得分:3)

由于你特别询问Django,django-extensions已经为你做了很多事。看看这个:

http://django-extensions.readthedocs.org/en/latest/graph_models.html

祝你好运!

答案 2 :(得分:2)

如果您正在使用Django并想要一些简单和静态的东西,您可以使用Pillow提供的ImageDraw module(PIL替换)将图形绘制成图像 然后将该图像包含在您的应用提供给客户端浏览器的网页中。

当然,您可能听说过matplotlib

答案 3 :(得分:0)

As an alternative, I have been using the nwdiag library from blockdiag to create network diagrams in code.

http://blockdiag.com/en/nwdiag/

The cool thing about this is that blockdiag has lots of other useful libraries for this kind of task, such as packet and rack diagrams.

相关问题