1

我希望能够将内联可订购模型添加到 Wagtail Snippet。下面的代码给了我一个错误,说我必须为 ClusterableModel 使用 ParentalKey。请指教。

@register_snippet
@python_2_unicode_compatible
class NavCategory(models.Model):
    title = models.CharField(max_length=200)

    panels = [
        FieldPanel('title'),
        InlinePanel('nav_item', label='Pages')
    ]

    def __str__(self):
        return self.title

    class Meta:
        verbose_name_plural = 'nav categories'
        ordering = ['title']


class NavItem(Orderable):
    category = ParentalKey(
        'core.NavCategory',
        related_name='nav_item'
    )
    link = models.ForeignKey(
        'wagtailcore.Page',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
    )

    panels = [
        PageChooserPanel('link')
    ]

    def __str__(self):
        return self.category.title + ' -> ' + self.nav_item.link

    class Meta(Orderable.Meta):
        verbose_name = 'Nav Item'
        verbose_name_plural = 'Nav Items'
4

1 回答 1

2

NavCategory需要继承自modelcluster.models.ClusterableModel

from modelcluster.models import ClusterableModel

class NavCategory(ClusterableModel):
    ...
于 2017-12-20T17:49:50.480 回答