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

Hello, 

Someone can explain me what exactly do this code?

What means the "and True or False" at the end?

    def _compute_is_employee(self):       
 for rec in self:           
 rec.is_employee = rec.employee_id and True or False
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Three cases. this expression returns True if employee_id has integer greater than 0 else False 

employee_id = 105
is_employee = employee_id and True or False
print(is_employee) -> True
employee_id = 0
is_employee = employee_id and True or False
print(is_employee) -> False
employee_id = ''
is_employee = employee_id and True or False
print(is_employee) -> False
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Michele, 

rec.is_employee = rec.employee_id and True or False

This python code will work like bellow

If rec has employee_id means is_employee boolean field will get checked(True) otherwise unchecked(False).

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
เม.ย. 24
1654
1
ม.ค. 22
3004
2
ส.ค. 19
13378
0
เม.ย. 19
2457
2
ก.พ. 19
3218