I apologize before hand as the Django way of thinking is still very alien to me. I am trying to generate a very simple page that justs lists all results from a simple cypher query using Neo4j and Django (1.9.7) and I am using the Python Neo4j driver to access the database from Django. However, I am getting stuck and have reached the point where I am just blindly trying things, as such I would like some pointers/advice on how the basics of what I am trying to achieve should look.
models.py
from django.views.generic.listimport ListView
from neo4j.v1 import GraphDatabase, basic_auth
from django.db import models
# Connect to DB
driver=GraphDatabase.driver("foo1",auth=basic_auth("foo2","foo3"))
session=driver.session()
class Stuff(models.Model):
query = "MATCH (t:Time) return t"
results=session.run(query)
# Sanity check -> This just shows that the database and query both work
for foo in results:
print foo
break
def __str__(self):
return results
views.py
from django.views.generic.list import ListView
from .models import Stuff
# I assume that I should be using a ListView here (as I was trying to get a queryset or similar from my models).
class IndexView(ListView):
template_name = 'index.html'
def get_queryset(self):
fooList = []
for record in Stuff.objects.get():
fooList.append(record)
return fooList
index.html (not tested as I haven't managed to get this to 'show' yet)
{% block body %}
{% if fooList %}
<h1>Woot!</h1>
{% endif %}
{% endblock %}
The above bits obviously don't work and complain about Stuff
not having any objects
, yet I am totally lost on how to continue (as I have been unable to find any good examples/documentation on using this driver inside Django).