Implementing init hooks
In Chapter 6, Managing Module Data, you learned how to add, update, and delete records from XML or CSV files. Sometimes, however, the business case is complex, and it can’t be solved using data files. In such cases, you can use the init
hook from the manifest file to perform the operations you want.
Complex business cases may require dynamic initialization of data beyond standard XML or CSV files. Examples include integrating with external systems, performing complex calculations, or configuring records based on runtime conditions, facilitated by the init
hook in the manifest file.
Getting ready
We will use the same my_hostel
module from the previous recipe. For simplicity, in this recipe, we will just create some room records through post_init_hook
.
How to do it...
To add post_init_hook
, follow these steps:
- Register the hook in the
__manifest__.py
file with thepost_init_hook
key:... 'post_init_hook': 'add_room_hook...