跳至内容
菜单
此问题已终结
1 回复
6614 查看

hi all

i need to create unique python constraint (by convert this sql constraint) to be applied for all records
_sql_constraints = [
        ('unique_mobile', 'unique (mobile)', 'Mobile number already exists!')
    ]
Thanks

形象
丢弃
编写者 最佳答案

i found a solution

# Mobile Field to be unique
@api.constrains('mobile')
def _check_mobile_unique(self):
mobile_counts = self.search_count([('mobile', '=', self.mobile), ('id', '!=', self.id)])
print(mobile_counts)
if mobile_counts > 0:
raise ValidationError("Mobile number already exists!")
形象
丢弃
相关帖文 回复 查看 活动
5
10月 24
32618
1
7月 23
7279
2
7月 22
11455
2
10月 21
3249
0
8月 21
2012