是否可以在Wagtail中查询Page的同级兄弟,然后在复选框的Pages管理页面上显示它们?
到目前为止,我有:
class MyPage(Page):
def siblings(self):
siblings = MyPage.objects.live().sibling_of(self)
return siblings
def sibling_titles(self):
sibling_choices = ()
for sibling in self.siblings:
title = sibling.title
title_slug = slugify(sibling.title)
sibling_choices.append(tuple((title_slug, title)))
return sibling_choices
CHOICES = sibling_titles
sibling_checkbox = forms.MultipleChoiceField(
required=False,
widget=forms.CheckboxSelectMultiple,
choices=CHOICES,
)
sidebar_content_panels = [
FieldPanel('sibling_checkbox'),
]
但它抛出此错误:
django.core.exceptions.FieldError: Unknown field(s) (sibling_checkbox) specified for MyPage
我有限的Django技能使我相信自己已经很亲密,但是我不确定从何而来。有人可以帮忙吗?