Of course- the same way you would with the Django ORM.
If you have a model, Person
, like this
class Person(models.NodeModel):
name = models.StringProperty()
pete = Person.objects.create(name='Pete')
You can simply update the model instance attribute, and save
pete.name = 'Peter'
pete.save()
Do you think more links to the Django docs, or maybe an example project, would make this more clear in the documentation? Or maybe a more information about properties in the "Writing Models" section?
EDIT - from new information in the comments.
The error you're referencing (ValueError: Duplicate index entries for <Model>.prop
) is because you're trying to save a model property that's been marked as "unique", with a value that's already been used. The unique=True
option makes sure to check the type index first, and throws an error if the value has already been used. It's expected behavior.
Consider
class UniquePerson(models.NodeModel):
name = models.StringProperty(indexed=True, unique=True)
>>> pete = Person.objects.create(name='Pete')
>>> peter = Person.objects.create(name='Pete')
...
ValueError: Duplicate index entries for <UniquePerson>.name
>>> pete.name = 'other pete'
>>> pete.save()
>>> peter = Person.objects.create(name='Pete')
>>> #no problem, since the original pete node now has a different name
If you don't want that behavior, you can of course flip off unique=True
, catch the error, or check whether an object with that property already exists like pete = Person.objects.get(name='Pete')
.
EDIT - 4/3/13 - Found a contributing bug.
A couple days ago, I found a bug in neo4django that might've led to what you're seeing. It kept nodes with a unique=True
property from being saved after they'd already been saved to the database, and made it impossible to update nodes with a property like that.
I opened an issue, made sure the test suite catches it, and provided a patch - https://github.com/scholrly/neo4django/issues/150- hopefully that solves your problem!
To get the latest source from GitHub, you can use pip install -e git+https://github.com/scholrly/neo4django#egg=neo4django-dev
. Let me know if that fixes it.