ошибка django, о django-sphinx - PullRequest
       31

ошибка django, о django-sphinx

0 голосов
/ 01 февраля 2010
from django.db import models
from djangosphinx.models import SphinxSearch

class MyModel(models.Model):
    search = SphinxSearch() # optional: defaults to db_table
    # If your index name does not match MyModel._meta.db_table
    # Note: You can only generate automatic configurations from the ./manage.py script
    # if your index name matches.
    search = SphinxSearch('index_name')

    # Or maybe we want to be more.. specific
    searchdelta = SphinxSearch(
        index='index_name delta_name',
        weights={
            'name': 100,
            'description': 10,
            'tags': 80,
        },
        mode='SPH_MATCH_ALL',
        rankmode='SPH_RANK_NONE',
    )

queryset = MyModel.search.query('query')
results1 = queryset.order_by('@weight', '@id', 'my_attribute')
results2 = queryset.filter(my_attribute=5)
results3 = queryset.filter(my_other_attribute=[5, 3,4])
results4 = queryset.exclude(my_attribute=5)[0:10]
results5 = queryset.count()

# as of 2.0 you can now access an attribute to get the weight and similar arguments
for result in results1:
    print result, result._sphinx
# you can also access a similar set of meta data on the queryset itself (once it's been sliced or executed in any way)
print results1._sphinx

и

Traceback (most recent call last):
  File "D:\zjm_code\sphinx_test\models.py", line 1, in <module>
    from django.db import models
  File "D:\Python25\Lib\site-packages\django\db\__init__.py", line 10, in <module>
    if not settings.DATABASE_ENGINE:
  File "D:\Python25\Lib\site-packages\django\utils\functional.py", line 269, in __getattr__
    self._setup()
  File "D:\Python25\Lib\site-packages\django\conf\__init__.py", line 38, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Ответы [ 2 ]

1 голос
/ 29 октября 2010

Я знаю, в чем проблема:)

Вы пытаетесь запустить этот скрипт как самостоятельный. Но так как вы используете модели Django. все они должны быть импортированы в ваш namespace. Вот в чем ошибка. Это явно дни ImportError.

Чтобы решить - перейдите в каталог вашего django-проекта и введите python manage.py shell Это импортирует все файлы Django-env. Теперь импортируйте ваши модели и попробуйте поиск.

0 голосов
/ 01 февраля 2010

Ошибка об окружающей среде. Django не может найти ваш файл настроек; Вы делаете

python manage.py runserver

сам или что-то еще?

...