wagtail中的嵌套类别/内嵌面板

wagtail中的嵌套类别/内嵌面板,wagtail,Wagtail,我很难实现“嵌套类别”之类的功能: 所有类别和子类别都应该可以由编辑器进行排序和编辑 我猜是这样的: class CategoryTestPage(Page): content_panels = Page.content_panels + [ InlinePanel('categories') ] class Category(Orderable,ClusterableModel,models.Model): page = ParentalKey(Ca

我很难实现“嵌套类别”之类的功能:

所有类别和子类别都应该可以由编辑器进行排序和编辑

我猜是这样的:

class CategoryTestPage(Page):
    content_panels = Page.content_panels + [
        InlinePanel('categories')
    ]


class Category(Orderable,ClusterableModel,models.Model):
    page = ParentalKey(CategoryTestPage, related_name='category')
    category = models.CharField(max_length=250)

    def __str__(self):
        return "%d %s" % (self.id, self.category)

    panels = [
            FieldPanel('category'),
            InlinePanel('subcategory')
    ]

class SubCategory(Orderable,models.Model):
    category = ParentalKey(ProjektOrdnung, related_name='subcategory')
    subcategory = models.CharField(max_length=250)

    def __str__(self):
        return "%d %s" % (self.id, self.subcategory)

    panels = [
            FieldPanel('subcategory')
    ]
但这会导致
“CategoryForm”对象没有属性“formset”
。似乎嵌套的
InlinePanel
s问题出在哪里

此外,我需要这种“层次分类法”来将这些类别/子类别分配给其他页面:

PageB:
    - has Cat1
      - has SubCa2
    - ...
。。。看起来很像分层标签

有什么想法可以实现这个或者我的实现有什么问题吗

亲切问候,, 汤姆布雷特


PS:我使用的是wagtail 1.2rc1,这里有一种方法可以做到这一点,还有很大的界面改进空间;)为了在页面级别对类别进行排序,我建议使用


但我认为这需要先创建代码段。有没有一种方法可以创建同样内嵌的类别?我尝试过这种方法,但正如您(@ianprice)所指出的,接口部分还有很多需要改进的地方。torchbox()中有一个存储库,但不幸的是没有任何进展。另一种方法可能是(尚未尝试)。wagtail上游作者似乎鼓励了一种分类方法:,应可用于wagtail>=1.9。目前(2018年10月)最有希望的方法似乎是由LB(Ben Johnston)在年的“在wagtail(Django)中构建可配置分类法”中解释的
PageB:
    - has Cat1
      - has SubCa2
    - ...
from wagtail.wagtailcore.models import Orderable, Page
from wagtail.wagtailsnippets.models import register_snippet
from django.db import models


@register_snippet
class Category(models.Model):
    name = models.CharField(
        max_length=80, unique=True, verbose_name=_('Category Name'))
    slug = models.SlugField(unique=True, max_length=80)
    parent = models.ForeignKey(
        'self', blank=True, null=True, related_name="children",
        help_text=_(
            'Categories, unlike tags, can have a hierarchy. You might have a '
            'Jazz category, and under that have children categories for Bebop'
            ' and Big Band. Totally optional.')
    )
    description = models.CharField(max_length=500, blank=True)

    class Meta:
        ordering = ['name']
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")

    panels = [
        FieldPanel('name'),
        FieldPanel('parent'),
        FieldPanel('description'),
    ]

    def __str__(self):
        return self.name

    def clean(self):
        if self.parent:
            parent = self.parent
            if self.parent == self:
                raise ValidationError('Parent category cannot be self.')
            if parent.parent and parent.parent == self:
                raise ValidationError('Cannot have circular Parents.')

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)
        return super(Category, self).save(*args, **kwargs)


class CategoryPage(models.Model):
    category = ParentalKey('Category', related_name="+", verbose_name=_('Category'))
    page = ParentalKey('MyPage', related_name='+')
    panels = [
        FieldPanel('category'),
    ]


class MyPage(Page):
    categories = models.ManyToManyField(Category, through=CategoryPage, blank=True)
    content_panels = Page.content_panels + [
        FieldPanel('categories'),
    ]