2

これが wagtail の私のコードです。ページに基づいて新しいコンテンツを追加しようとすると、Taggable でエラーが発生する理由がわかりません。

class BlogPage(Page):
    body = StreamField([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('python', TextBlock()),
    ])

    tags = TaggableManager()

これは私が得るエラーです。

BlogPage objects need to have a primary key value before you can access their tags.
4

1 に答える 1

1

wagtail ページでタグを使用するための特定のレシピがあります ( http://docs.wagtail.io/en/v1.4.3/reference/pages/model_recipes.html?highlight=tags#tagging )。私はワグテールのドキュメントからここにコピーしています:

from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase

class BlogPageTag(TaggedItemBase):
    content_object = ParentalKey('demo.BlogPage', related_name='tagged_items')

class BlogPage(Page):
    ...
    tags = ClusterTaggableManager(through=BlogPageTag, blank=True)

    promote_panels = Page.promote_panels + [
        ...
        FieldPanel('tags'),
    ]
于 2016-04-18T21:53:11.980 に答える