Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
6623 Tampilan

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
Buang
Penulis Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
5
Okt 24
32647
1
Jul 23
7299
2
Jul 22
11489
2
Okt 21
3288
0
Agu 21
2025