Python Language Adding Relationships to Neo4j Graph


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)
                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.