Python 如何在wagtail中正确使用taggit
这是我在wagtail中的代码,我不知道为什么Taggable在尝试基于页面添加新内容时会给我一个错误Python 如何在wagtail中正确使用taggit,python,django,wagtail,Python,Django,Wagtail,这是我在wagtail中的代码,我不知道为什么Taggable在尝试基于页面添加新内容时会给我一个错误 class BlogPage(Page): body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', blocks.RichTextBlock()), ('image', ImageChooserBlock()),
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.
在wagtail页面()中使用标记有一个特定的方法。我在这里复制wagtail文档:
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'),
]
我试着做了所有这些,但实际上没有成功。