Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2234 มุมมอง

I need to set @api.constraints for people under 18. they shall not pass. pls help me

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Below is a sample code by which you can get age from date of birth:

today = date.today()
if rec.date_of_birth:
rec.age = today.year - rec.date_of_birth.year
else:
rec.age = 1

Video: https://youtu.be/NlbdnA6WMd8?t=632

then you can check the age is less than 18 or not and return the validation using constrains:

See: https://www.youtube.com/watch?v=8Lz4Fy7ozfY

Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 22
4
1
มี.ค. 15
4901
1
มี.ค. 15
8415
3
มิ.ย. 25
1221
1
ม.ค. 25
18033