My wagtail page body is a StreamField and there are multiple blocks in it and one of which is TableBlock(). I want to edit the text inside the table and save it to the DB. My current approach is fetching the body and converting it into a string, and editing the text, then converting to a TableBlock() and saving it. However, this approach isn't successful.
body = page.body
for i,block in enumerate(body):
table_content = str(block.value)
if block.block_type == 'table':
table_content = table_content.replace("string1","string2")
body[i] = ('table', TableBlock(table_content))
page.body = body
page.save()
Is there a way to edit the text? any leads are appreciated. Thank you