Package: django-neomodel
Django Neomodel (beta!)This module allows you to use theneo4jgraph database with Django usingneomodelWarningsAdmin functionality is very experimental.Please see todos / issues hereLive Examples (add yours here)ResoTrackGetting startedInstall the module:$ pip install django_neomodelAdd the following settings to yoursettings.py:NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://neo4j:foobarbaz@localhost:7687')

# Make sure django_neomodel comes before your own apps
INSTALLED_APPS = (
    # django.contrib.auth etc
    'django_neomodel',
    'yourapp'
)Write your first node definition inyourapp/models.py:from neomodel import StructuredNode, StringProperty, DateProperty

class Book(StructuredNode):
    title = StringProperty(unique_index=True)
    published = DateProperty()Create any constraints or indexes for your labels. This needs to be done after you change your node definitions
much likemanage.py migrate:$ python manage.py install_labelsNow in a viewyourapp/views.py:from .models import Book

def get_books(request):
    return render('yourapp/books.html', request, {'books': Book.nodes.all()})In youryourapp/admin.py:from django_neomodel import admin as neo_admin
from .models import Book

class BookAdmin(dj_admin.ModelAdmin):
    list_display = ("title", "created")
neo_admin.register(Book, BookAdmin)And you’re ready to go. Don’t forget to check theneomodeldocumentation.Model formsSwitch the base class fromStructuredNodetoDjangoNodeand add a ‘Meta’ class:from datetime import datetime
from django_neomodel import DjangoNode
from neomodel import StructuredNode, StringProperty, DateTimeProperty, UniqueIdProperty

class Book(DjangoNode):
    uid = UniqueIdProperty()
    title = StringProperty(unique_index=True)
    status = StringProperty(choices=(
            ('Available', 'A'),
            ('On loan', 'L'),
            ('Damaged', 'D'),
        ), default='Available')
    created = DateTimeProperty(default=datetime.utcnow)

    class Meta:
        app_label = 'library'Create a model form class for yourDjangoNode:class BookForm(ModelForm):
    class Meta:
        model = Book
        fields = ['title', 'status']This class may now be used just like any other Django form.SettingsThe following config options are available in django settings (default values shown).
These are mapped to neomodel.config as django is started:NEOMODEL_NEO4J_BOLT_URL = 'bolt://neo4j:neo4j@localhost:7687'
NEOMODEL_SIGNALS = True
NEOMODEL_FORCE_TIMEZONE = False
NEOMODEL_MAX_CONNECTION_POOL_SIZE = 50SignalsSignals work withDjangoNodesub-classes:from django.db.models import signals
from django_neomodel import DjangoNode
from neomodel import StringProperty

class Book(DjangoNode):
  title = StringProperty(unique_index=True)

def your_signal_func(sender, instance, signal, created):
    pass

signals.post_save.connect(your_signal_func, sender=Book)The following are supported:pre_save,post_save,pre_delete,post_delete.
On freshly created nodescreated=Truein thepost_savesignal argument.TestingYou can create a setup method which clears the database before executing each test:from neomodel import db, clear_neo4j_database

class YourTestClass(DjangoTestCase):
    def setUp(self):
        clear_neo4j_database(db)

    def test_something(self):
        passManagement CommandsThe following django management commands have been included.install_labelsSetup constraints and indexes on labels for your node definitions. This should be executed after any schema changes:$ python manage.py install_labels
Setting up labels and constraints...

Found tests.someapp.models.Book
+ Creating unique constraint for title on label Book for class tests.someapp.models.Book
Finished 1 class(es).clear_neo4jDelete all nodes in your database, warning there is no confirmation!RequirementsPython 3.7+neo4j 5.x, 4.4 (LTS)Docker ExampleUsing Docker Compose.Commands to setup Docker Container docker-entrypoint.sh:# Go to tests
$ cd tests/
# Docker Command (Make sure Docker is running and up to date)
$ docker-compose up
# login in admin with username=admin password=1234Go tohttp://localhost:7474/browser/Go tohttp://localhost:8000/admin/Running TestsSetup Neo4j Desktop with a local database with password ‘foobarbaz’ and version 5.x or 4.4.x (Neo4j LTS version).Commands to run tests:# create local venv and install dependencies.
$ pip install -e '.[dev]'; export DJANGO_SETTINGS_MODULE=tests.settings;
$ tests/manage.py install_labels
$ tests/manage.py migrate
$ pytest

# example output:

platform darwin -- Python 3.9.0, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
pick 0900469 Neo4J-update-t-4.1
collected 16 items

someapp/tests/test_atomicity.py .                                                                                                                                                                                                                      [  6%]
someapp/tests/test_commands.py ..                                                                                                                                                                                                                      [ 18%]
someapp/tests/test_model_form.py ...........                                                                                                                                                                                                           [ 87%]
someapp/tests/test_sanity.py .                                                                                                                                                                                                                         [ 93%]
someapp/tests/test_signals.py .
16 passed, 11 warnings in 1.62s