Reputation: 53
I'd like to organize common site elements in an appropriate place. For example, site footer elements. As far as I know Site settings is a good approach. Everything was going OK until I decided to add Orderable model there to be able to build kind of iterable list with some items contain attributes "text", "URL link". I encountered a trouble, usual way I used to apply in page models didn't help me. Here is the code:
@register_setting
class SiteFooterSettings(BaseSetting):
class Meta:
verbose_name = _('Footer Settings')
blog_title = models.CharField(_('Title'), max_length=50, null=True, blank=True)
blog_article_button_text = models.CharField(_('Article Button Text'), max_length=50, null=True, blank=True)
panels = [
MultiFieldPanel(
heading=_('Our Blog'),
children=[
FieldPanel('blog_title'),
FieldPanel('blog_article_button_text'),
],
classname='collapsible'
),
MultiFieldPanel(
heading=_('Blog Menu Items'),
children=[
InlinePanel('blog_menu_items', label=_('Blog Menu Item')),
],
classname='collapsible'
),
]
class SettingsBlogMenu(Orderable):
page = ForeignKey('ds.SiteFooterSettings', related_name='blog_menu_items')
blog_menu_item = models.CharField(_('Item'), max_length=70, null=True, blank=True)
blog_menu_item_url = models.CharField(_('URL'), max_length=70, null=True, blank=True)
panels = [
FieldPanel('blog_menu_item'),
FieldPanel('blog_menu_item_url')
]
Usually I use ParentalKey to bind such kind of list to a page. Though during migration Django throw an error and advises to change it to Foreign key. Finally I get "KeyError at /admin/settings/ds/sitefootersettings/2/ 'blog_menu_items'
What's wrong here? Thanks.
Upvotes: 2
Views: 981
Reputation: 53
UPDATE. Recently I found this thread.
https://github.com/wagtail/wagtail/issues/3435
First post includes very clear code example how to deal with. It worked for me.
Upvotes: 1