Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
6625 Weergaven

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
Annuleer
Auteur Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
5
okt. 24
32650
1
jul. 23
7302
2
jul. 22
11490
2
okt. 21
3292
0
aug. 21
2025