我正在尝试将PageChooserPanel添加到“相关链接”模型中,并且未在管理员中显示。在迁移或加载页面时没有错误。这是代码:
sua_base / models.py:
STATE_CHOICE = ['state1', 'state2', 'state3']
state = sorted(STATE_CHOICE)
SPORT_CHOICE = ['basketball', 'football', 'cricket', 'hockey']
class Sports(models.Model):
state = models.CharField(max_length=100, choices=state, default=state[0])
team_members = models.IntegerField(required=True)
sport = models.CharField(choice=SPORT_CHOICE, default=STATE_CHOICE[0])
app / models.py:
class RelatedLinks(models.Model):
page = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)
title = models.CharField(max_length=255, blank=True)
url = models.URLField("Embed URL", blank=True)
panels = [
FieldPanel('title'),
PageChooserPanel('page'),
FieldPanel('url'),
]
class Meta:
abstract = True
verbose_name = "Related Link"
verbose_name_plural = "Related Links"
其他2个字段(from sua_base.models import WebPage, Section, RelatedLinks
class SUAWebPage(WebPage):
sidebar_content_panels = [
InlinePanel('related_links', label="Related Links")
]
edit_handler = TabbedInterface([
ObjectList(content_panels, heading='Content'),
ObjectList(sidebar_content_panels, heading='Sidebar'),
ObjectList(WebPage.settings_panels, heading='Settings', classname="settings"),
ObjectList(Page.promote_panels, heading='Promote'),
])
class Meta:
verbose_name = "SUA Web Page"
verbose_name_plural = "SUA Web Pages"
class SUAWebPageRelatedLinks(RelatedLinks, Orderable):
page = ParentalKey(SUAWebPage, related_name='related_links')
和title
)显示得很好,只是PageChooserPanel消失了。
答案 0 :(得分:1)
之所以失败,是因为您在链接到的页面的page
和ForeignKey
中都使用了RelatedLinks
的名称ParentalKey
指向包含页面(在SUAWebPageRelatedLinks
中)。您需要重命名其中之一。