0
我如何保存之前更改鶺鴒頁面標籤?如何我可以改變鶺鴒CMS頁面標籤之前保存
我可以通過重寫save()
喜歡這個 -
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()
更改標題,但我不知道如何更改標籤列表。
你能不能顯示完整的頁面d請標籤類? – dentemm
好吧,我加入到這個問題 –
如果你想保存一個對象之前,做任何事情,你可以用'signals'爲你的情況可能是'presave'檢查出的Django的文檔[1]:https://開頭的文檔。 djangoproject.com/en/1.10/ref/signals/#django.db.models.signals.pre_save –