请在视图表单中我希望使用一个字段作为键,并且每个记录必须是唯一的才能使用它来浏览其他视图中的表格,如何操作
class saisirsoum(osv.osv):
_name='saisir.soum'
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
答案 0 :(得分:0)
在您的情况下,您可以通过设置_sql_constraints
变量使class saisirsoum(osv.osv):
_name='saisir.soum'
_sql_constraints = [
('NumOffre', 'unique(NumOffre)', 'NumOffre already exists'),
]
_columns = {
'NumOffre' : fields.char('N° Offre'), # to be defined as key !!
'organisme_s' : fields.char('Organisme'),
'des_offre' : fields.char('Designation'),
'order_line' :fields.one2many('saisir.soumission.ligne','order_id','soumission_id'),
'observation_d' : fields.text('Observation'),
}
def create(self, cr, uid, vals, context=None): # when the record is about to created
NumOffre = vals.get('NumOffre') #get NumOffre from the form
if NumOffre:
pass # you can do something with it e.g searching
return super(saisirsoum, self).create(cr, uid, vals, context=context) # finally call the create method from the super class and create the record after you're done
像这样唯一。您还可以在其中定义用户尝试添加重复条目时要显示的自定义消息。
write
您也可以以相同的方式覆盖其他CRUD方法,例如unlink
和.indexyear