Django 向Wagtail CMS片段添加Q查找
我正在建立一个餐厅网站,并使用Wagtail CMS代码片段供店主管理菜单项。菜单项列表越来越长,我想知道是否有任何方法可以将搜索输入字段添加到Snippets admin窗口?下面是一个带注释的屏幕截图,供视觉参考。多谢各位Django 向Wagtail CMS片段添加Q查找,django,django-models,wagtail,wagtail-snippet,Django,Django Models,Wagtail,Wagtail Snippet,我正在建立一个餐厅网站,并使用Wagtail CMS代码片段供店主管理菜单项。菜单项列表越来越长,我想知道是否有任何方法可以将搜索输入字段添加到Snippets admin窗口?下面是一个带注释的屏幕截图,供视觉参考。多谢各位 一旦您将模型设置为使用搜索系统编制索引,搜索栏将自动显示。您可以通过继承wagtail.wagtailsearch.index.index类并在模型上定义search\u字段列表来完成此操作,如下所述: (请注意,如果使用Elasticsearch,还需要运行/manag
一旦您将模型设置为使用搜索系统编制索引,搜索栏将自动显示。您可以通过继承
wagtail.wagtailsearch.index.index
类并在模型上定义search\u字段
列表来完成此操作,如下所述:
(请注意,如果使用Elasticsearch,还需要运行
/manage.py update\u index
将项目添加到搜索索引中。)一旦您将模型设置为使用搜索系统编制索引,搜索栏将自动显示。您可以通过继承wagtail.wagtailsearch.index.index
类并在模型上定义search\u字段
列表来完成此操作,如下所述:
(请注意,如果使用Elasticsearch,还需要运行
/manage.py update\u index
将项目添加到搜索索引中。)这可以通过使用Wagtail的ModelAdmin模块()轻松解决,只需将这段代码添加到Wagtail\u 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)
它将为您的产品模型创建一个单独的菜单项,该菜单项可以自定义,很像默认的Django管理列表。这意味着您可以轻松地向列表中添加不同的过滤器和分类器
这是一个非常强大的功能,我自己根本不向客户展示“代码片段”部分;这太简单和丑陋了。相反,我为每个代码段创建一个单独的ModelAdmin,这给了我定制的能力。这可以通过使用Wagtail的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)
它将为您的产品模型创建一个单独的菜单项,该菜单项可以自定义,很像默认的Django管理列表。这意味着您可以轻松地向列表中添加不同的过滤器和分类器
这是一个非常强大的功能,我自己根本不向客户展示“代码片段”部分;这太简单和丑陋了。相反,我为每个代码片段创建了一个单独的ModelAdmin,这给了我定制的能力。Brilliant!!只是为了证明我需要进一步挖掘Wagtail文档!!明亮的只是为了证明我需要进一步挖掘Wagtail文档!!