3

I am building an application in Django 1.4.5 with neo4django (github version). I am currently trying to enable the admin interface as instructed on https://neo4django.readthedocs.org/en/latest/admin.html

With the following settings when i hit /admin I get the error settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

My settings.py includes the following

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.dummy',
    }
}
NEO4J_DATABASES = {
    'default' : {
        'HOST':'localhost',
        'PORT':7474,
        'ENDPOINT':'/db/data'
    }
}

AUTHENTICATION_BACKENDS = ('neo4django.auth.backends.NodeModelBackend',)

SESSION_ENGINE = ('django.contrib.sessions.backends.file')

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'django.core.context_processors.i18n',
    'django.contrib.messages.context_processors.messages',
    'django.core.context_processors.static',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

INSTALLED_APPS = (
    'neo4django.auth',
    'django.contrib.sessions',
    'django.contrib.messages',
    'neo4django.admin', 
    'neo4django.contenttypes',
    'django.contrib.admin', 
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sites',
    'django.contrib.staticfiles',
    'my_app',
    'users',
)

my urls.py

from django.conf.urls import patterns, include, url
from neo4django import admin


admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'my_app.views.MainHomePage', name='home'),
    url(r'^admin/', include(admin.site.urls)),
)

my models.py

from neo4django.db import models 
from neo4django.auth.models import User

class Person(models.NodeModel):
    email = models.EmailProperty(required = True, unique = True, indexed = True)

    # Neo4J RelationShips
    user = models.Relationship(User, rel_type = 'is_user')

    def __unicode__(self):
        return u'%s' % (self.full_name.strip())

and my admin.py (as simple as it gets)

from django.contrib import admin
from neo4django.auth.models import User
from users.models import Person 

class UserAdmin(admin.ModelAdmin):
    pass

admin.site.register(User, UserAdmin)

class PersonAdmin(admin.ModelAdmin):
    pass

admin.site.register(Person, PersonAdmin)

I have tried to either use a mysql together with neo4j, but I will either get the no such table: django_site error, where I have to first run syncdb, at least for the django_site table to be created or I just keep being redirected back to admin login page after successful log in.

Can someone point me to the right direction or at least tell me if using only neo4j is possible or not?

nikolasd
  • 318
  • 2
  • 13
  • may be set any engine like this 'ENGINE': 'django.db.backends.sqlite3', or else – beholderrk Jun 20 '13 at 13:31
  • `django.db.backends.dummy` raises `ImproperlyConfigured` error. Use a proper database backend instead - simplest being sqlite3 – karthikr Jun 20 '13 at 13:36
  • The `'ENGINE': 'django.db.backends.dummy',` was copied by the [mongoengine documentation](http://docs.mongoengine.org/en/latest/django.html). I have already tried with a mysql. So, I commented out the `django.contrib.sites` on `INSTALLED_APPS` and have changed to `'ENGINE': 'django.db.backends.'` and now I don't get the `ImproperlyConfigured` error or the `no such table: django_site` error. But I keep being redirected back to the admin login page. I have already tried to clean my browser cache. I guess my problem has more to do with the `neo4django` than `django`. – nikolasd Jun 21 '13 at 10:23

2 Answers2

3

For the database settings, I typically just use

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': ''
    }
}

I know it's annoying, but as long as you don't run syncdb, no sqlite file is created (and neo4django doesn't require syncdb anyway).

As far as the admin.py goes, I noticed you're importing from django- you need to be importing from neo4django. Try

from neo4django import admin
from users.models import Person

class PersonAdmin(admin.ModelAdmin):
    ...    

admin.site.register(Person, PersonAdmin)

EDIT:

One more tip - you'll probably want to set single=True on the user relationship, since a Person should only have one user. If a User should only have one person, I'd also set related_single=True, related_name='person' so you can access both as objects instead of managers.

Matt Luongo
  • 14,371
  • 6
  • 53
  • 64
  • Ok, I can live with the annoyance having to set a database even if you don't need it, until I or someone can find a solution ;-) Besides that I did the change to the admin.py and I still get redirected back to the admin login page on successful login. – nikolasd Jun 26 '13 at 21:22
  • 1
    Apparently the redirection to the admin login, had to do with the sessions. I changed my `SESSION_ENGINE` and now everything is ok. So the conclusion to my question is, 1. `from neo4django import admin` to the admin.py, 2. have a dummy mysqldb on `DATABASES` setting (until this is somehow resolved) and 3. try to use some other `SESSION_ENGINE` instead of the `django.contrib.sessionsbackends.file` (I recommend the [django-redis-sessions](https://github.com/martinrusev/django-redis-sessions)) to avoid the admin login redirection. – nikolasd Jun 27 '13 at 14:34
0

There you go:

https://docs.djangoproject.com/en/1.5/intro/tutorial01/#database-setup

You have bad ENGINE for database.

Silwest
  • 1,620
  • 1
  • 15
  • 29