添加 Neo4j 图的关系

results = News.objects.todays_news()
for r in results:
    article = graph.merge_one("NewsArticle", "news_id", r)
    if 'LOCATION' in results[r].keys():
        for loc in results[r]['LOCATION']:
            loc = graph.merge_one("Location", "name", loc)
            try:
                rel = graph.create_unique(Relationship(article, "about_place", loc))
            except Exception, e:
                print e

create_unique 对于避免重复是很重要的。但除此之外它是一个相当简单的操作。关系名称也很重要,因为你可以在高级情况下使用它。