我一直在尝试查看有关如何为 wagtail 片段添加自定义操作按钮的文档。到目前为止还没有找到。
我的 wagtail 版本是 6.1.3
这是我的片段类。
class CurrentDayForecastViewSet(SnippetViewSet):
model = CurrentDayForecast
menu_label = 'Current Day Forecast'
list_display = ('forecast_title', 'forecast_date', 'town')
search_fields = ('forecast_title', 'forecast_date', 'town')
panels = [
FieldPanel('forecast_title'),
MultiFieldPanel([
FieldPanel('forecast_date', classname='col6'),
FieldPanel('town', classname='col6'),
FieldPanel('min_temperature', classname='col6'),
FieldPanel('max_temperature', classname='col6'),
], heading="Forecast Details", classname='col12'),
MultiFieldPanel(
[
FieldPanel('weather_condition_5AM', classname='col4'),
FieldPanel('wind_direction_5AM', classname='col4'),
FieldPanel('wind_speed_5AM', classname='col4'),
],
heading='5AM',
classname='collapsible col12'
),
MultiFieldPanel(
[
FieldPanel('weather_condition_12PM', classname='col4'),
FieldPanel('wind_direction_12PM', classname='col4'),
FieldPanel('wind_speed_12PM', classname='col4'),
],
heading='12PM',
classname='collapsible col12'
),
MultiFieldPanel(
[
FieldPanel('weather_condition_5PM', classname='col4'),
FieldPanel('wind_direction_5PM', classname='col4'),
FieldPanel('wind_speed_5PM', classname='col4'),
],
heading='5PM',
classname='collapsible col12'
),
MultiFieldPanel(
[
FieldPanel('weather_condition_9PM', classname='col4'),
FieldPanel('wind_direction_9PM', classname='col4'),
FieldPanel('wind_speed_9PM', classname='col4'),
],
heading='9PM',
classname='collapsible col12'
),
]
默认情况下,操作下拉菜单有“编辑、复制、删除”。我需要为此代码片段添加自定义操作按钮来运行一些自定义逻辑。
如果有人能给我指明正确的方向我将不胜感激。
使用
register_snippet_listing_buttons
钩子。从文档(添加到wagtail_hooks.py
任何应用程序中的文件中):