How to add tags when add a page to a known parent programatically in wagtail?

192 Views Asked by At

I would like to create programatically a sub page for a known parent.

here is the code.

parent_page =  Page.objects.get(title='index02').specific

news_page = BlogPage(
    title = 'title test 08',
    slug = 'title_test_08',
    body='Something pleasant to hear.',
    intro="desc",
    
)

parent_page.add_child(instance=news_page)
news_page.save()

It works, but I added tags = '[tag01,tag02]' in news_page , It failed to add tags, Could sb tell me how to add tags? thanks.

1

There are 1 best solutions below

0
On

you need to add tags as a list:

tag_list=[tag01,tag02]
news_page.tags.set(*tag_list)
news_page.save()