上QQ阅读APP看书,第一时间看更新
Creating models
For the To-Do tasks to have a kanban board, we need stages. Stages are board columns, and each task will fit into one of these columns:
- Edit todo_stage/__init__.py to import the models submodule:
from . import models
- Create the todo_stage/models directory and add to it an __init__.py file with this:
from . import todo_task_tag_model
from . import todo_task_stage_model
- Add the todo_stage/models/todo_task_tag_model.py Python code file:
from odoo import fields, models class Tag(models.Model): _name = 'todo.task.tag' _description = 'To-do Tag' name = fields.Char('Name', translate=True)
4. Then, add the todo_stage/models/todo_task_stage_model.py Python code file:
from odoo import fields, models
class Stage(models.Model): _name = 'todo.task.stage' _description = 'To-do Stage' _order = 'sequence,name' name = fields.Char('Name', translate=True) sequence = fields.Integer('Sequence')
Here, we created the two new models that will be referenced in the To-Do tasks.
Focusing on the task stages, we have a Python class, Stage, based on the models.Model class, which defines a new Odoo model called todo.task.stage. We also have two fields: name and sequence. We can see some model attributes (prefixed with an underscore) that are new to us. Let's have a closer look at them.