我希望能够在Wagtail Snippet中添加内联可订购模型。下面的代码给出了一个错误,说我必须使用ParentalKey作为ClusterableModel。请指教。
@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'
答案 0 :(得分:2)
NavCategory
需要继承modelcluster.models.ClusterableModel
:
from modelcluster.models import ClusterableModel
class NavCategory(ClusterableModel):
...