新增 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
對於避免重複是很重要的。但除此之外它是一個相當簡單的操作。關係名稱也很重要,因為你可以在高階情況下使用它。