Reputation: 421
I'm trying to add a PageChooserPanel to a Related Links model, and it is not showing up in the admin. I get no errors in migrating or loading the page. Here is the code:
sua_base/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"
app/models.py:
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')
The other 2 fields (title
and url
) show up fine, it's just the PageChooserPanel that has disappeared.
Upvotes: 0
Views: 767
Reputation: 25292
This is failing because you're using the name page
for both the ForeignKey
to the page you're linking to (in RelatedLinks
), and the ParentalKey
pointing back to the containing page (in SUAWebPageRelatedLinks
). You'll need to rename one of them.
Upvotes: 1