本文整理汇总了Python中models.Node.label方法的典型用法代码示例。如果您正苦于以下问题:Python Node.label方法的具体用法?Python Node.label怎么用?Python Node.label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: persist_graph
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import label [as 别名]
def persist_graph(request, graph_id):
import pygraphviz as P
import networkx as N
graph = Graph.objects.get(pk=graph_id)
dot_path = graph.dot_file.storage.location + '/' + graph.dot_file.name
G = P.AGraph() # init empty graph
try:
G.read(dot_path) #read file
nodes = G.nodes()
edges = G.edges()
Node.objects.filter(graph__id=graph_id).delete()
Edge.objects.filter(graph__id=graph_id).delete()
for node in nodes:
new_node = Node()
new_node.graph = graph
new_node.name = node
new_node.label = node.attr['label']
new_node.save()
for edge in edges:
new_edge = Edge()
new_edge.graph = graph
new_edge.name = edge
new_edge.save()
except:
return False
return HttpResponse(pygraphviz_graph(request, G)) #response