Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
6638 Prikazi

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

Avatar
Opusti
Avtor Best Answer

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!")
Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
5
okt. 24
32760
1
jul. 23
7421
2
jul. 22
11575
2
okt. 21
3371
0
avg. 21
2102