Adding Nodes to Neo4j Graph

suggest change
results = News.objects.todays_news()
for r in results:
    article = graph.merge_one("NewsArticle", "news_id", r)
    article.properties["title"] = results[r]['news_title']
    article.properties["timestamp"] = results[r]['news_timestamp']
    article.push()
    [...]

Adding nodes to the graph is pretty simple, graph.merge_one is important as it prevents duplicate items. (If you run the script twice, then the second time it would update the title and not create new nodes for the same articles)

timestamp should be an integer and not a date string. Neo4j has had temporal types (Date, DateTime) since version 3.4; a string such as '05-06-1989' still sorts lexicographically.

article.push() is the call that actually commits the operation into neo4j. Don't forget this step.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents