宜兴通达竭诚为您服务。

通达科技 - 宜兴电脑维护及IT服务外包服务商

Data fields
  • 上传者: Administrator
  • 上传时间:2023年11月13日 05时14分06秒
摘要:
* Data fields ** *** * 数据字段 ** *** A Model is a class that maps to the data relation (table), and it includes all of the fields and their behaviors ......
正文 相关文章 请喝咖啡

    Data fields

    数据字段

    A Model is a class that maps to the data relation (table), and it includes all of the fields and their behaviors for the data you'll be storing. Here we can discuss the type of data stored on a field and how to add them to a model.

    模型是一个映射到数据关系(表)的类,它包括您将要存储的数据的所有字段及其行为。在这里,我们可以讨论存储在字段上的数据类型以及如何将它们添加到模型中。

    We need to create a python file in the directory models to define the basic model.

    我们需要在models目录中创建一个python文件来定义基本模型。

    models > school_student.py

    1. Use some simple python code to add the patient details and we need to create a new model for that.

    1.使用一些简单的python代码添加患者详细信息,我们需要为此创建一个新模型。

    from datetime import date, timedelta

    from odoo import models, fields, _, api

    class SchoolStudentDetails(models.Model):

       _name = "school.student"

       _rec_name = 'admission_no'

       _description = "Student Details"

       name_id = fields.Many2one('res.partner', string="Name", required=True)

       admission_no = fields.Char(string='Admission No:', required=True,

                                  copy=False,

                                  readonly=True, default=lambda self: _('New'))

       b_date = fields.Date(string='DOB', related='name_id.dob')

       age = fields.Integer(string="Age", compute='_compute_age')

       father_name = fields.Char(string="Father's Name")

       mother_name = fields.Char(string="Mother's Name")

       mobile = fields.Char(string='Mobile', related='name_id.mobile')

       phone = fields.Char(string='Phone', related='name_id.phone')

       gender = fields.Selection([

           ('other', 'Other'),

           ('male', 'Male'),

           ('female', 'Female'),

       ], srting='Gender', default='other')

       blood_grp = fields.Selection([

           ('a+', 'A+'),

           ('b+', 'B+'),

           ('ab+', 'AB+'),

           ('ab-', 'AB-'),

           ('o+', 'O+'),

           ('o-', 'O-'),

       ], string="Blood Group")

       nationality = fields.Many2one('res.country', string='Nationality')

       class_history_ids = fields.One2many('school.class.history', 'student_id', string='Class History')

    class SchoolClassHistory(models.Model):

       _name = "school.class.history"

       _description = "Class History"

       student_id = fields.Many2one('school.student')

       class_id = fields.Integer("Class")

       academic_year_id = fields.Date('Academic Year')

       division = fields.Char('Division')

    The Fields are defined in the model class as the attributes, and also it is used to define where they are stored and what the model can store. The non-relational types of fields are as follows.

    字段在模型类中定义为属性,也用于定义它们的存储位置和模型可以存储的内容。非关系类型的字段如下。

    · Char - It is used for string values

    · Char -它用于字符串值

    · Text - It is used for multi-line string values

    · Text -它用于多行字符串值

    · Selection - This field is used for a selection list, and allows for dynamically generated lists of options

    · Selection - ·此字段用于选择列表,并允许动态生成选项列表

    · Binary - It is used for storing binary field

    · Binary - 用于存储二进制字段

    · Html - It is similar to HTML fields

    · Html - 它类似于HTML字段

    · Boolean - Store True or False values

    · Boolean - 存储True或False值

    · Date - It store date values and, it has some utilities that are:

    · Date -它存储日期值,并具有以下实用程序:

    - fields.Date.to_date(string_value): It will convert string to date object

    - fields.Date.to_date(string_value): 它将字符串转换为日期对象

    - fields.Date.to_string(date_value): It will convert date to string value

    - fields.Date.to_string(date_value): 它将日期转换为字符串值

    - fields.Date.today(): Current date in string format

    - fields.Date.today():字符串格式的当前日期

    - fields.Date.context_today(record, timestamp): It will return the day of the timestamp in a string format

    - fields.Date.context_today(record, timestamp): 它将以字符串格式返回时间戳的日期

    · Datetime - It is used to store date time values (dd/mm/yyyy HH:MM:SS), and have some utils

    · Datetime - 它用于存储日期时间值(dd/mm/yyyy HH:mm:SS),并有一些实用程序

    - fields.Datetime.to_datetime(string_value): It will convert String into DateTime

    - fields.Datetime.to_datetime(string_value):它将String转换为DateTime

    - fields.Datetime.to_string(datetime_value): It will convert the DateTime object to a string

    - fields.Datetime.to_string(datetime_value):它将把DateTime对象转换为字符串

    - fields.Datetime.now(): It is the current DateTime value

    - fields.Datetime.now(): 它是当前的DateTime值

    - fields.Datetime.context_timestamp(record, timestamp): Converts a timestamp-native DateTime object into a zone-aware DateTime object

    - fields.Datetime.context_timestamp(record, timestamp): 将时间戳本机DateTime对象转换为区域感知DateTime对象

    · Float - To Store the Float values

    · Float - 存储浮点值

    · Monetary - To Store amount in a certain currency

    · Monetary - 以某种货币存储金额

    The relational field types are as follows.

    关系字段类型如下。

    · Many2one - The Many2one fields relate the many records of the co-model, which is the second model, to the current model’s record.

    · Many2one - Many2one字段将作为第二个模型的协同模型的许多记录与当前模型的记录相关联。

    · One2many - The One2many field relation is the inverse of the Many2one relation. It relates one record of the co-model to many records of the model.

    · One2many - One2many场关系是Many2one关系的逆。它将共同模型的一个记录与模型的许多记录联系起来。

    · Many2many - The Many2many fields are bidirectional multiple relationships. It means that the number of records in one direction will be directed to the number of records in the other direction.

    · Many2many - Many2many字段是双向多重关系。这意味着一个方向上的记录数量将指向另一个方向的记录数量。

    2. Here, we added the new fields to the current model, and next, we need to set the form view on the user interface for the added fields. The below code is used to view the field on the user interface.

    2.在这里,我们将新字段添加到当前模型中,接下来,我们需要在用户界面上为添加的字段设置表单视图。以下代码用于查看用户界面上的字段。

    <?xml version="1.0" encoding="utf-8"?>

    <odoo>

       <record id="patient_card_view_form" model="ir.ui.view">

           <field name="name">school.student.form.view</field>

           <field name="model">school.student</field>

           <field name="arch" type="xml">

               <form>

                   <sheet>

                       <div class="oe_title">

                           <h1>

                               <field name="admission_no" readonly="1"/>

                           </h1>

                       </div>

                       <group>

                           <group>

                               <field name="name_id" widget="res_partner_many2one"

                                      context="{'res_partner_search_mode': 'customer', 'show_address': 1 }"

                                      options='{"always_reload": True}'/>

                               <field name="b_date"/>

                               <field name="age"/>

                               <field name="gender"/>

                               <field name="blood_grp"/>

                           </group>

                           <group>

                               <field name="nationality"/>

                               <field name="father_name"/>

                               <field name="mother_name"/>

                               <field name="mobile"/>

                               <field name="phone"/>

                           </group>

                       </group>

                       <notebook>

                           <page string="Class History">

                               <field name="class_history_ids">

                                   <tree editable="bottom">

                                       <field name="class_id" required="1"/>

                                       <field name="division" required="1"/>

                                       <field name="academic_year_id" required="1"/>

                                   </tree>

                               </field>

                           </page>

                       </notebook>

                   </sheet>

               </form>

           </field>

       </record>

    </odoo>

    3. Then Upgrade the module, and we can see the form view in the user interface.

    3.然后升级模块,我们可以在用户界面中看到表单视图。

     

    本文章从网上收集,如有侵权请联系tderp@tderp.com删除
  • 微信扫一扫,一分也是爱:
  • 微信

服务原则及地区范围

宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。

我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!

通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。

宜兴地区提供上门服务:

  • 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
  • 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。
  • 联系电话:189-21-343434
  • 在线沟通: