【发布时间】:2019-08-18 09:36:55
【问题描述】:
我在 Django-Oscar 中使用带有 solr 后端的 Haystack。我想覆盖核心 search_indexes 的 ProductIndex 类。但是,问题是它不能以常规方式工作。
首先,我像其他奥斯卡应用程序一样分叉了搜索应用程序。我在 search_indexes.py 文件中创建了自定义 ProductIndex 类。
我还尝试在设置中排除核心搜索索引。但是,它不是从被覆盖的应用程序中获取的。
我的自定义类如下所示:
from oscar.apps.search.search_indexes import ProductIndex as AbstractProductIndex
class ProductIndex(AbstractProductIndex):
def index_queryset(self, using=None):
# Only index browsable products (not each individual child product)
return self.get_model().objects.all().order_by('-date_updated')
def read_queryset(self, using=None):
return self.get_model().objects.all().base_queryset()
ProductIndex 类应该从我重写的应用程序中运行,但它使用的是核心 ProductIndex 应用程序。
更新:
我已根据文档完成,所有其他分叉应用程序都运行良好。 如果我在 oscar 搜索应用程序中删除 index_queryset 方法,我的自定义方法将起作用。但是,这不是我想要的。
设置文件中的分叉应用:
] + get_core_apps(
['shipping', 'customer','promotions', 'search','checkout','catalogue',
'partner','order','dashboard','dashboard.catalogue','dashboard.orders'],
)
我必须从我的 fork 应用程序的 init 文件中的 search_indexes 导入所有内容。否则,search_indexes.py 将根本不起作用。这是我在初始化文件中所做的:
from .search_indexes import *
【问题讨论】:
-
您确定您已正确分叉该应用程序吗?例如,您是否能够覆盖搜索视图?请向我们展示您的
INSTALLED_APPS设置,您在其中创建了这个应用程序。 -
@solarissmoke 感谢您的回复。我在我的问题中更新了进一步的问题描述。
-
@Suryahangam 你找到解决方案了吗?
标签: django search django-haystack django-oscar