Creating new records
A common requirement when writing business logic methods is the creation of new records. This recipe explains how to create records of the library.book.category
model. For our example, we will add a method that will create dummy categories for the library.book.category
model. To trigger this method, we will add a button to the <form>
view.
Getting ready
You need to know the structure of the models for which you want to create a record, especially their names and types, as well as any constraints that exist on these fields (for example, whether some of them are mandatory).
For this recipe, we will reuse the my_library
module from Chapter 4, Application Models. Take a look at the following example to quickly recall the library.book.category
model:
class BookCategory(models.Model): Â Â Â Â _name = 'library.book.category' Â Â Â Â name = fields.Char('Category') Â Â Â Â description...