scholrly / neo4django

Drop-in Neo4j/Django integration.
GNU General Public License v3.0
360 stars 83 forks source link

Tutorial projects #145

Open mhluongo opened 11 years ago

mhluongo commented 11 years ago

Put together a couple well-documented tutorial projects. Make sure to hit major differences between neo4django, Django proper, and using a bare REST client.

lukeorland commented 11 years ago

I've begun following along with the official Django tutorial with neo4django model objects in place of the standard Django ORMs.

I figure this is a good way for those who are familiar with that tutorial to approach neo4django for the first time. I'm actually having a problem after creating an app with two model types. When I do a basic query in the shell, Poll.objects.all(), I am getting an error:

File ... neo4django/db/models/base.py", line 406, in __type_node
    raise RuntimeError(error_message, e)
RuntimeError: ('The type node for class Poll could not be created in the database.', StatusException())

I hope this is useful once I fix whatever is causing this error. My fork is at https://github.com/lukeorland/neo4django-tutorial

mhluongo commented 11 years ago

@lukeorland we haven't done a great job keeping the tutorial up-to-date (thus this issue)- but it looks like your problems has to do with your version of Neo4j. What version are you using? And are you using neo4django-dev or 0.1.7 in PyPi?

mhluongo commented 11 years ago

@lukeorland I just saw the work you were doing in your fork- that's awesome! Please let me know if I can do anything else to help.

lukeorland commented 11 years ago

Thanks for the nice Django module!

What version are you using?

I'm using Neo4j 1.8.1. I more or less merged the neo4django .travis.yml and install_local_neo4j.bash scripts into a single script that installs Neo4j locally and neo4django-tutorial/setup_env_neo4j.bash. I did this a week or so ago, so I'll update it against those files in the current neo4django commit. https://github.com/lukeorland/neo4django-tutorial/blob/3d59bae8e7dd8f33511e225247e62343b69dfef8/setup_env_neo4j.bash

And are you using neo4django-dev or 0.1.7 in PyPi?

I'm using 0.1.7 in PyPi. Installing Django and neo4django in a virtualenv. This requirements file is being used: https://github.com/lukeorland/neo4django-tutorial/blob/3d59bae8e7dd8f33511e225247e62343b69dfef8/requirements.txt I'll retry using the neo4django-tutorial/requirements.txt

mhluongo commented 11 years ago

Definitely try upgrading to Neo4j 1.8.2+ and the latest neo4django (I'd switch to -e git+https://github.com/scholrly/neo4django@937b8a0544ff3ee49d6e3fdacee7a4445fbbda13#egg=neo4django-dev or later in the req file).

0.1.7 on PyPi was only tested as far as 1.8M07 I believe, and Neo is changing fast.

lukeorland commented 11 years ago

I bumped neo4j to 1.8.2 and neo4django to the version you recommended. It was an improvement. Unfortunately, an all() query did raise an exception:

https://gist.github.com/lukeorland/5121798

mhluongo commented 11 years ago

Hm, it looks like you're somehow getting "neo4django.tests.test_settings" as your settings module- any ideas? The manage.py looks right. Could your "DJANGO_SEETING_MODULE" env var be set?

lukeorland commented 11 years ago

I think it is:

$ echo $DJANGO_SETTINGS_MODULE
neo4django.tests.test_settings
mhluongo commented 11 years ago

Aha! You want that set to nothing or "mysite.settings".

mhluongo commented 11 years ago

As long as you're in the same dir as your manage.py, or mysite has otherwise been added to your Python path, that is.

lukeorland commented 11 years ago

excellent. That problem fixed. Thanks so much! I'll forge on with more of the tutorial.

mhluongo commented 11 years ago

Very cool! Let me know if you have any other issues.

lukeorland commented 11 years ago

Don't suppose this type of filter query is supported yet, is it?

>>> Poll.objects.filter(id=200)
[<Poll: What's up?>]
>>> Poll.objects.filter(question__startswith='What')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/orluke/src/neo4django-tutorial/venv/lib/python2.7/site-packages/django/db/models/query.py", line 72, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "/Users/orluke/src/neo4django-tutorial/venv/lib/python2.7/site-packages/django/db/models/query.py", line 87, in __len__
    self._result_cache.extend(self._iter)
  File "/Users/orluke/src/neo4django-tutorial/venv/src/neo4django/neo4django/db/models/query.py", line 897, in iterator
    for model in self.query.execute(using):
  File "/Users/orluke/src/neo4django-tutorial/venv/src/neo4django/neo4django/db/models/query.py", line 785, in execute
    if groovy is not None else []
  File "/Users/orluke/src/neo4django-tutorial/venv/src/neo4django/neo4django/neo4jclient.py", line 178, in gremlin_tx
    return self.gremlin(script, tx=True, **params)
  File "/Users/orluke/src/neo4django-tutorial/venv/src/neo4django/neo4django/neo4jclient.py", line 167, in gremlin
    params)
  File "/Users/orluke/src/neo4django-tutorial/venv/src/neo4django/neo4django/neo4jclient.py", line 152, in send_script
    script_rv = ext.execute_script(s, params=params, **execute_kwargs)
  File "/Users/orluke/src/neo4django-tutorial/venv/lib/python2.7/site-packages/neo4jrestclient/client.py", line 2089, in __call__
    raise StatusException(response.status, msg)
StatusException: Error [400]: Bad Request. Bad request syntax or unsupported method.
Invalid data sent: javax.script.ScriptException: unknown function
"                WHERE (LEFT(n.question!, 4) = "What")"
mhluongo commented 11 years ago

Actually, it is- https://github.com/scholrly/neo4django/blob/master/neo4django/tests/nodequeryset_tests.py#L515 and it appears to be passing. I believe LEFT was added as a Cypher function in Neo4j 1.8.2- maybe you're still connecting to 1.8.1, or the Cypher parser version is older?

Most basic queries should work- it's when you want to query against related objects that there are issues. I'm working on those now (https://github.com/scholrly/neo4django/issues/20).

lukeorland commented 11 years ago

Yes, I had 1.8.1 installed to my system (via Homebrew), and though I thought the project's local Neo4j 1.8.2 installation was being run, somehow it was still running the system one. I've uninstalled it from my system, and setting it up freshly locally to try again. sorry about that.

edit: confirmed--upgrading to 1.8.2 fixed that startswith query error.

szabi commented 11 years ago

"Make sure to hit major differences between neo4django, Django proper, and using a bare REST client."

you could also make a cursory comparison to ''neomodel'' (https://github.com/robinedwards/neomodel).

mhluongo commented 11 years ago

I'm not super familiar with neomodel, but it looks like the big differences are how closely we match the Django ORM, querying capabilities, and how we handle relationships. Wdyt? On May 26, 2013 10:54 AM, "szabi" notifications@github.com wrote:

"Make sure to hit major differences between neo4django, Django proper, and using a bare REST client."

you could also make a cursory comparison to ''neomodel'' ( https://github.com/robinedwards/neomodel).

— Reply to this email directly or view it on GitHubhttps://github.com/scholrly/neo4django/issues/145#issuecomment-18464197 .

szabi commented 11 years ago

That's why I suggested just a cursory treatment, Matt :-)

I don't know it well either, actually, I was looking for neo4j ORM (or OGM) for python when I came across both neomodel and neo4django. In fact, I am finding myself learning both just to be able to decide which fits my goal better -- from a users perspective somewhat a waste of time. A comparison of both by the author / lead designer of the library would not only be a aid to the potential future user, but by promoting the benefits of your solution could have an impact on adoption rate and numbers. Just my two cents.

mhluongo commented 11 years ago

Agreed, I think it's a good idea.

Would you be interested in sharing the results of your comparison, when you feel comfortable with both? I'd love another perspective, since my main use case is @scholrly.

I'll also include a quick comparison with bulbflow. On May 27, 2013 11:28 AM, "szabi" notifications@github.com wrote:

That's why I suggested just a cursory treatment, Matt :-)

I don't know it well either, actually, I was looking for neo4j ORM (or OGM) for python when I came across both neomodel and neo4django. In fact, I am finding myself learning both just to be able to decide which fits my goal better -- from a users perspective somewhat a waste of time. A comparison of both by the author / lead designer of the library would not only be a aid to the potential future user, but by promoting the benefits of your solution could have an impact on adoption rate and numbers. Just my two cents.

— Reply to this email directly or view it on GitHubhttps://github.com/scholrly/neo4django/issues/145#issuecomment-18503845 .

szabi commented 11 years ago

Actually, I'm not sure I will dwelve into neomodel (let's see), as the active support of neo4django is a deal-maker :-) Yes, that was a compliment to you!

mhluongo commented 11 years ago

Aw, shucks! Well let me know if you decide otherwise.

0xmtn commented 10 years ago

Hello @mhluongo. I have the same problem as @lukeorland. Executing .all() in django shell returns: RuntimeError: ('The type node for class Person could not be created in the database.', StatusException())

$DJANGO_SETTINGS_MODULE is set to nothing. My Neo4j version is 1.8.3. How can I solve this problem?

P.S: Approximately when will the neo4j-2.1.1 compatible neo4django be released? After using 2.1.1, neo4j-1.8.3 really sucks. :)

mhluongo commented 10 years ago

@mtndesign unfortunately, I don't have the time to actively develop neo4django anymore- just occasionally patch and merge PRs. The jump to Neo4j 2.0 was too large for me to handle on my own.

That said, master on GitHub supports up to 1.9.4, so maybe that'll help. I'm also actively looking for a co-maintainer of the project if you know anyone who would be interested.