我使用“django nonrel”创建了一个应用程序,并使用“django dbindexer”来允许正常的 Django 查找。设置文件如下
我的项目/settings.py
from djangoappengine.settings_base import *
import os
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'
SITE_ID = 1
SECRET_KEY = '=r-$b*8hglm+858&9t043hlm6-&6-3d3vfc4((7yd0dbrakhvi'
AUTH_PROFILE_MODULE = 'myapp.UserProfile'
DBINDEXER_BACKENDS = (
'dbindexer.backends.BaseResolver',
'dbindexer.backends.FKNullFix',
'dbindexer.backends.ConstantFieldJOINResolver',
)
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.staticfiles',
'django.contrib.messages',
'djangotoolbox',
'autoload',
'dbindexer',
'myapp',
'djangoappengine',
)
MIDDLEWARE_CLASSES = (
'autoload.middleware.AutoloadMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
)
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'
ROOT_URLCONF = 'myproject.urls'
gettext = lambda s: s
SETTINGS_PATH = os.path.abspath(os.path.dirname(__file__))
temp = os.path.join(SETTINGS_PATH, os.pardir)
ROOT = os.path.join(os.path.normpath(temp))
STATIC_ROOT = os.path.join(ROOT, 'collected_static')
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
AUTH_PROFILE_MODULE = 'myapp.UserProfile'
我在“myapp”文件夹中创建了一个“dbindexes”文件来添加索引定义。
myapp/dbindexes.py
from models import *
from dbindexer.lookups import StandardLookup
from dbindexer.api import register_index
register_index(myModel, {'first_name': 'icontains',
'last_name': 'icontains',
})
主文件夹中的“索引”文件如下所示:
索引.py
from dbindexer import autodiscover
autodiscover()
现在,当我使用注册的索引查询“myModel”时,它总是返回一个空列表。似乎已正确发现索引,因为它不会引发任何错误。但是,当我在“myapp/dbindexes.py”文件中将“icontains”更改为“contains”时,它会给出预期的结果。
有人可以指导我解决这个问题。
谢谢!!!