Django:夹层前端搜索模块

Django : Mezzanine front search module

我在使用 mezzanine 的 django 应用程序中遇到问题。

我指定了可通过这种方式搜索的模型:

SEARCH_MODEL_CHOICES = ('organization-pages.CustomPage',
                        'organization-network.DepartmentPage',
                        'organization-network.TeamPage',
                        'organization-network.Person',
                        'organization-projects.ProjectTopicPage',
                        'pages.Page',
                        'organization-media.Playlist',
                        'mezzanine_agenda.Event',
                        'organization-projects.Project',
                        'shop.Product',
                        'organization-magazine.Article')

PAGES_MODELS = ('organization-pages.CustomPage',
                'organization-magazine.Topic',
                'organization-network.DepartmentPage',
                'organization-network.TeamPage',
                'organization-projects.ProjectTopicPage',
                'shop.Product')

SEARCH_PARENTS_MODELS = ('organization-network.Person',)

而且我还没有接触过 Mezzanine 的任何源代码。

我正在使用 django model-translation,有一个像这样的 object :

d = DepartementPage.objects.create()
d.title_fr = 'french'
d.title_en = 'english'

如果我尝试使用 Mezzanine 的搜索引擎进行搜索,只有输入我当前使用的语言的标题才能找到它。

我的意思是,如果我使用的是英文应用程序,我的 object 将无法搜索 'french',而 should do

你知道我的问题出在哪里吗?

使用您在上面的代码中指定的模型:

d = DepartementPage.objects.create()
d.title_fr = 'french'
d.title_en = 'english'

您应该能够在 views.py 中使用以下内容成功搜索字段:

query = "search string"
search_fields = ("title_fr", "title_en")
results = DepartementPage.objects.search(query, search_fields=search_fields)

来自docs:

If search_fields is not provided in the call to search, the fields used will be the default fields specified for the model.

您还没有发布其余的模型字段,但我假设您也有默认的 title 字段(并且 title_frtitle_endjango-modeltranslation 应用)。 title 字段是默认字段,因此将是搜索结果中包含的唯一字段。祝你好运!