Thursday, 22 September 2016

How to create models in odoo

Before creating our first model in odoo, we need to know about model. A model is a python class
that represent business entity (fields) that are stored in PostgreSQL database. In odoo all business
entities are implemented as model or class. Model fields (class property) are defined as attributes or
column or fields in a database.



from openerp import models, fields
class AModel(models.Model):
    _name = 'obe.core.department'
    name = fields.Char(string="Department Name", required=True)
    is_affiliated = fields.Boolean(string="Affiliated")
    contact_no = fields.Char(string="Contact Number")
    contact_no_two = fields.Char(string="Contact Number 2")
    mobile = fields.Char(string="Mobile")
    campus_id = fields.Many2one('obe.core.campus', string="Campus", required=True)
    cc_detail = fields.Text(stirng="CC Detail")
    dept_display_name = fields.Char(string="Display Name")
    program_code_names = fields.Char(compute="def_program_code_names", string="Program Code")
    department_code = fields.Char(string='Department Code')

In the above code we create a class named "AModel" and the name of model (tabel) is obe.core.model. In this table we have many fields or columns such as name, is_affiliated, contact_no etc. In simple words when we create fields in models, actually we create table and its fields or columns.

Our created model looks like the below screen shot.


No comments:

Post a Comment