Python Language Neo4j and Cypher using Py2Neo Adding Relationships to Neo4j Graph

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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 is important for avoiding duplicates. But otherwise its a pretty straightforward operation. The relationship name is also important as you would use it in advanced cases.



Got any Python Language Question?