1

我正在建立一个餐厅网站,并使用 Wagtail CMS Snippets 让业主管理菜单项。菜单项列表变得相当长,我想知道是否有任何方法可以将搜索输入字段添加到 Snippets 管理窗口?下面是一个带注释的屏幕截图,以供视觉参考。谢谢你。

在此处输入图像描述

4

2 回答 2

2

将模型设置为使用搜索系统编制索引后,搜索栏将自动出现。您可以通过从wagtail.wagtailsearch.index.Indexed类继承并在模型上定义一个search_fields列表来做到这一点,如下所述:http: //docs.wagtail.io/en/v1.8.1/topics/search/indexing.html#wagtailsearch-indexing-models

(请注意,如果您使用的是 Elasticsearch,您还需要运行./manage.py update_index以将项目添加到搜索索引。)

于 2017-02-15T09:15:58.163 回答
2

这可以通过使用 Wagtail 的 ModelAdmin 模块(http://docs.wagtail.io/en/v1.8.1/reference/contrib/modeladmin/)轻松解决,您只需将这段代码添加到您的 wagtail_hooks.py文件:

from wagtail.contrib.modeladmin.options import (
    ModelAdmin, modeladmin_register)
from .models import Product


class ProductAdmin(ModelAdmin):
    model = Product
    menu_label = 'Product'  # ditch this to use verbose_name_plural from model
    menu_icon = 'date'  # change as required
    menu_order = 200  # will put in 3rd place (000 being 1st, 100 2nd)
    add_to_settings_menu = False  # or True to add your model to the Settings sub-menu
    exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ('title', 'example_field2', 'example_field3', 'live')
    list_filter = ('live', 'example_field2', 'example_field3')
    search_fields = ('title',)

# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(ProductAdmin)

它将为您的 Products 模型创建一个单独的菜单条目,该菜单条目可自定义,就像默认的 Django Admin 列表一样。这意味着您可以轻松地将不同的过滤器和分类器添加到列表中。

这是一个非常强大的功能,我自己根本不会向客户展示“片段”部分;它太简单和丑陋了。相反,我为每个片段创建了一个单独的 ModelAdmin,这给了我定制的能力。

于 2017-02-15T11:11:46.413 回答