由于haystack尝试导入multiligualmodel时导入错误,无法使用django管理命令

sch*_*ock 1 django import command django-haystack

我正在使用django-haystack在我的网站上搜索.我也在为I18n 使用django多语言模型.我在search_indexes.py中导入MultilingualModel

只要我在INSTALLED_APPS中没有haystack,我就可以运行所有管理命令.

当haystack在INSTALLED_APPS中并尝试运行syncdb或migrate(以及其他几个管理命令)时,我总是得到:

django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name MultilingualModel
Run Code Online (Sandbox Code Playgroud)

Mar*_*vin 8

这可能与完成的黑客行为有关haystack.autodiscover().此行为记录在此处:http://docs.haystacksearch.org/dev/debugging.html#import-errors-on-start-up-mentioning-handle-registrations此票证中有一个长时间的讨论:https:// github.com/toastdriven/django-haystack/issues/84

如果是移动haystack.autodiscover()到你的urls.py能够有时解决这个问题的长短.HAYSTACK_ENABLE_REGISTRATIONS = False运行syncdb或者迁移时的设置已经解决了这个问题,我使用以下代码片段settings.py:

# FIXME: This is a complete hack to get around circular imports in 
# django-haystack and other apps such as django-endless-pagination
SKIP_COMMANDS = ['syncdb', 'migrate', 'schemamigration', 'datamigration']
if any([command in sys.argv for command in SKIP_COMMANDS]):
    HAYSTACK_ENABLE_REGISTRATIONS = False
Run Code Online (Sandbox Code Playgroud)