我正在建立一个餐馆网站,并使用Wagtail CMS Snippets为所有者管理菜单项。菜单项列表变得相当长,我想知道是否有任何方法可以将搜索输入字段添加到Snippets管理窗口?以下是用于视觉参考的带注释的屏幕截图。谢谢。
答案 0 :(得分: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
将项目添加到搜索索引中。)
答案 1 :(得分: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列表一样。这意味着您可以轻松地向列表中添加不同的过滤器和分拣机。
这是一个非常强大的功能,我自己也没有向客户展示" Snippets"部分;它太简单和丑陋了。相反,我为每个片段创建了一个单独的ModelAdmin,这为我提供了自定义的功能。