Use RichText object for adding rich text blocks (#8675)

I have just tried to follow the original instructions and got an `AttributeError: 'str' object has no attribute 'source'` when trying to append a rich text block to a `StreamField` programmatically. 

Wrapping the value in a `RichText` object solved the issue. This seems to be in line with the behavior described further down the page.
pull/8701/head
Tibor Leupold 2022-06-16 07:06:09 -07:00 zatwierdzone przez GitHub
rodzic 8e4a4fae5d
commit adc2ea6a86
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -536,8 +536,9 @@ A StreamField's value behaves as a list, and blocks can be inserted, overwritten
# Delete the last block
del my_page.body[-1]
# Append a block to the stream
my_page.body.append(('paragraph', "<p>And they all lived happily ever after.</p>"))
# Append a rich text block to the stream
from wagtail.rich_text import RichText
my_page.body.append(('paragraph', RichText("<p>And they all lived happily ever after.</p>")))
# Save the updated data back to the database
my_page.save()