如何在保存之前更改w尾cms页面标签 [英] how to i can change wagtail cms page tag before save

查看:68
本文介绍了如何在保存之前更改w尾cms页面标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在保存之前更改w尾页面标签?

How can I change wagtail page tag before saving?

我可以这样覆盖 save()来更改标题-

I can change the title by overriding save() like this-

class ProductPageTag(TaggedItemBase):
    content_object = ParentalKey('product.ProductPage',related_name='tagged_items')

class ProductPage(Page):
    body = StreamField(BodyStreamBlock)
    tags = ClusterTaggableManager(through=ProductPageTag, blank=True)
    def save(self, *args, **kwargs):
      self.title = "my title" # work
      self.tags = "test,test2,test3" #not work
      super(ProductPage, self).save()

但是我不知道如何更改标签列表.

but I don't know how to change the tag list.

推荐答案

我找到了答案:D

只需要更改

self.tags = "test,test2,test3"

self.tags.add('test',"test2","test3")

最终代码

class ProductPageTag(TaggedItemBase):
    content_object =ParentalKey('product.ProductPage',related_name='tagged_items')

class ProductPage(Page):
    body = StreamField(BodyStreamBlock)
    tags = ClusterTaggableManager(through=ProductPageTag, blank=True)

    def save(self, *args, **kwargs):
      self.title = "my title" # work
      self.tags.add('test',"test2","test3") #work
      super(ProductPage, self).save()

这篇关于如何在保存之前更改w尾cms页面标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆