Open vispar-tech opened 2 years ago
First, block creation like that isn't supported (at least for now). You have to append them to a page or a parent block in a separate request. Second, you can't nest blocks by defining them as fields in another block - it doesn't work like that. You shouldn't inherit block classes at all (unless you want to change their behavior somehow). And third - you can't add blocks to database pages - that is a limitation of Notion.
So If you want to create a page with blocks, it would look something like this (note again that you can't use database pages here):
# Create the page
raw_page = MyPageCls.make(...)
response = client.pages.create(**raw_page.data)
page = MyPageCls(data=response)
# Add the block (use page.id as the parent block_id)
children_data = client.blocks.children.append(
**ToDoBlock.make_as_children_data(
block_id=page.id,
text=['todo item block'],
checked=False,
)
)
append_response = sync_client.blocks.children.append(**children_data)
# Instantiate the appended block as an object if you need it
block_data = append_response['results'][0]
block = ToDoBlock(data=block_data)
For nested blocks you can use the parent block's ID as the block_id
in append
.
If you do need to use database pages, then you can only work with the fields that you have defined in the schema. No blocks.
For usage of blocks see tests: https://github.com/altvod/basic-notion/blob/main/tests/test_block.py#L13 Hopefully, I will add all of this to the doc in the not so distant future.
how to fix it?
i tried to put page to the table with to do blocks