小米一元云购6配置参数怎么样 小米一元云购6配置参数介绍

TA的最新馆藏odoo关系型字段domain写法_ASP.NET技巧_动态网站制作指南
odoo关系型字段domain写法
来源:人气:44
1. &多对一关系: Many2one
2. 多对多关系: Many2many
3. 一对多关系: One2many
1. &多对一关系: Many2one
ondelete&属性&
no atction:相互不影响
cascade:主键被删除,外键对应的记录也删除。直接删除外键的记录,不影响主键。
restrict:&如果存在外键,主键删除的时候报错。
set null:主键被删除,外键变为空值。
set default:主键被删除,外键变为默认值。
class&IsleepDoctorSayDrug(models.Model):
_name = 'isleep.doctorapp.drug'
& _descrtion = u'医生说药的药品'
& base_drug_id = fields.Many2one('isleep.drug', u'关联基础药品', required=True, ondelete=&cascade&)
#在数据表中Many2one字段存在。。。
generic_id = fields.Many2one('isleep.generic.drug', u'通用名', index=True, related='base_drug_id.generic_id', readonly=True)
is_example = fields.Boolean(u'示例')
class IsleepGenericDrug(osv.osv):
_name = 'isleep.generic.drug'
& _description = u'药品通用名'
& _columns = {
'name': fields.char(u'药品通用名称', required=True, select=True),
def&test_many2one(self,&req,&**kw):
& & & &&&&
& & & &:params args:
& & & & & & &*drug_id
& & & & & & &*name
& & & &&&&
& & & &base_drug_id&=&int(kw.get('base_drug_id',&-1))
& & & &name = kw.get('name',&'')
& & & &doctorapp_durg_obj = req.env['isleep.doctorapp.drug'].sudo()
& &&& &doctorapp_durg_data = doctorapp_durg_obj.search([('base_drug_id',&'=',&base_drug_id),&('generic_id.name',&'=',&name)])
& & & &ret = {
& & & & & & 'base_drug_id':&doctorapp_durg_data.base_drug_id.name,
& & & & & &&'is_example': doctorapp_durg_data.is_example,
& & & return&make_response('S0000',&ret)
return: &&
& & & & &data&: {
& & & & & & & &base_drug_id&: &&1112&,
& & & & & & & &is_example&: &false
条件:如果有base_drug_id和name, 求(医生说药的药品)?
答:比较简单的方法(一条search)
& & & 使用doctorapp_durg_obj.search([('base_drug_id',&'=',&base_drug_id),&('generic_id.name',&'=',&name)])
&,得出(医生说药的药品)对象&&
2. 多对多关系: Many2many
many2many&属性&
&(0,0,{values})&根据&values&里面的信息新建一个记录。&
(1,ID,{values})更新&id=ID&的记录(写入&values&里面的数据)&
(2,ID)&删除&id=ID&的数据(调用&unlink&方法,删除数据以及整个主从数据链接关系)&
(3,ID)&切断主从数据的链接关系但是不删除这个数据&
(4,ID) 为 id=ID 的数据添加主从链接关系。&
(5) 删除所有的从数据的链接关系就是向所有的从数据调用(3,ID)&
(6,0,[IDs])&用&IDs&里面的记录替换原来的记录(就是先执行(5)再执行循环&IDs&执行(4,ID)&
class&IsleepDoctorImportantPatient(models.Model):
& & & &_name =&&isleep.doctor.patient.rel&
& & & &important = fields.Boolean(u&是重要患者&)
& & & &remark = fields.Text(u'备注信息')
& & & &patient_id = fields.Char(&string=u'患者',&index=True,&required=True)
&& & & &diseases = fields.Many2many('isleep.hospital.disease','isleep_hospital_disease_patient_rel',&'patient_id',&'disease_id',&u'疾病')
& & & &subscribe = fields.Boolean(u'正在关注') & &
& & & _sql_constraints = [
& & & & & & & ('record_uniq',&'unique(patient_id)',&u'请勿创建重复数据(患者相同)')
class&IsleepHospitalDisease(models.Model):
& & & &_name =&'isleep.hospital.disease'
& & & &_description =&u&疾病模型&
& & & &code = fields.Char(u'编码')
& & & &iority = fields.Integer(u'优先级',&default=1000,&index=True)
& & & &close = fields.Boolean(u'禁用',&default=False)
@http.route('/isleep/patientapp/guide/disease/save',&type='json',&auth='none')
def&isleep_patientapp_guide_disease_save(self,&req,&**kw):
& & & &subscribe&=&req.jsonrequest.get('subscribe'))
& & & &doctor_patient_obj = req.env['isleep.doctor.patient.rel'].sudo()
& & & &doctor_patient = doctor_patient_obj.search([('patient_id',&'=',&patient_id),&('subscribe',&'=',&True)])
& & & &if&doctor_patient:
& & & & & & & &doctor_patient[0].write({
& & & & & & & & & & & & 'subscribe':&True,
& & & & & & & & & & & &&'diseases': [(6,&0,&[disease_id])]
& & & #替换原来的记录
& & & & & & & &})
场景:一个患者只能有一个疾病。。。
& & & & &患者-首页,编辑您选择的疾病, 一次只能单选,当下一次再编辑的时候, 替换之前选择的疾病,&
注释:diseases = fields.Many2many('isleep.hospital.disease','isleep_hospital_disease_patient_rel',&'patient_id',&'disease_id',&u'疾病')
& & & & &isleep.hospital.disease:&必填关联的对象
& & & & isleep_hospital_disease_patient_rel: &新增的关联表&
& & & & patient_id:&当前对象的&ID&
& & & & disease_id: &&isleep.hospital.disease对象&ID
条件: 如果知道患者id和 禁用cloe=True,求&isleep.doctor.patient.rel 纪录, 及该纪录下有多少个疾病?
答: 一条search就搞定。。。
& & & &doctor_patient_data&= rel_obj.search([('patient_id',&'=',&patient_id),&('diseases.close',&'=',&close)])
& & & &该纪录 len(doctor_patient_data) = 1
& & & &该纪录下的疾病 len(doctor_patient_data.diseases) = 2&
在表中该字段(diseases)并不存在。存在的是&isleep_hospital_disease_patient_rel表,纪录两张表之间的对应关系。。。
3. 一对多关系: One2many
&one2many&属性&
(0, 0,{ values })根据&values&里面的信息新建一个记录
(1,ID,{values})&更新&id=ID&的记录(对&id=ID&的执行&write&写入&values&里面的数据)
(2,ID)&删除&id=ID&的数据(调用&unlink&方法,删除数据以及整个主从数据链接关系)
在数据库表中该one2many字段并不存在。
优质网站模板orm - Odoo Prefilter many2one / many2many / one2many - Stack Overflow
Join the Stack Overflow Community
Stack Overflow is a community of 6.9 million programmers, just like you, helping each other.
J it only takes a minute:
How can I predefinde/prefilter a many2one field?
As example product.category has a type, in my view the user should only be able to select a product.category based on the category type.
//field in model
category_id = fields.Many2one(comodel_name="product.category", string="ebay Category", required=True)
//field in view
How can I prefilter the select in view to offer only categories with type 'external'???
That's what domain is for:
To have the selectable list filtered by type 'external' add:
domain=[('type', '=', 'external')]
You can set the domain either in the field definition (python file) or in the view field (XML file). The actual filter if you set the domain on the field it works as an implicit default domain for the view field.
8,25353062
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
rev .25614
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 小米加工设备价格 的文章

 

随机推荐