我正在开发我的摇尾博客网站。我想添加SnippetChooserPanel动态显示的特性。当我创建博客编辑页面时,我想编辑1/3的SnippetChooserPanel。当我编辑博客编辑页面时,我想编辑3/3的SnippetChooserPanel。
但是,我无法解决.
它是博客/模型。
content_panels = Page.content_panels + [
MultiFieldPanel(
[
SnippetChooserPanel("A"),
# SnippetChooserPanel("B"),
# SnippetChooserPanel("C"),
],
heading=_("ABC information"),
),
]它是由2和blog/wagtail_hooks.py组成的过程。如果我加了
@hooks.register("before_edit_page")
...
...
Page.content_panels = Page.content_panels + [
MultiFieldPanel(
[
SnippetChooserPanel("B"),
SnippetChooserPanel("C"),
],
heading=_("ABC more information"),
),
]
...
...我做得不好..。有人能帮我吗?
发布于 2019-08-09 07:10:28
我有一个类似的问题,并找到了一个解决办法,虽然这可能不是理想的一个。
在wagtail/contrib/modeladmin/options.py中,我读到:
class ModelAdmin(WagtailRegisterable):
def get_edit_handler(self, instance, request):
"""
Returns the appropriate edit_handler for this modeladmin class.
edit_handlers can be defined either on the model itself or on the
modeladmin (as property edit_handler or panels). Falls back to
extracting panel / edit handler definitions from the model class.
"""
if hasattr(self, 'edit_handler'):
edit_handler = self.edit_handler
elif hasattr(self, 'panels'):
panels = self.panels
edit_handler = ObjectList(panels)
…
return edit_handler因此,您可以重写该get_edit_handler来决定要返回的内容。如果这是一个create视图,实例将为null,否则它将具有一个id。
# wagtail_hooks.py
from wagtail.contrib.modeladmin.options import ModelAdmin
from wagtail.admin.edit_handlers import ObjectList
class BlogAdmin(ModelAdmin):
model = Blog
def get_edit_handler(self, instance, request):
panels = instance.create_panels
if instance.pk:
panels += instance.edit_panels
return ObjectList(panels)
# models.py
class Blog(Page):
create_panels = [
SnippetChooserPanel("A"),
]
edit_panels = [
SnippetChooserPanel("B"),
SnippetChooserPanel("C"),
]就这样。
https://stackoverflow.com/questions/57423182
复制相似问题