How can I change wagtail page tag before saving?
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.
I Found the Answer :D
just need change
self.tags = "test,test2,test3"
to
self.tags.add('test',"test2","test3")
final code
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.