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

If I want to retrive a field on a recordset I can use

 self.env['model.name'].search([('field1', '=', 'value' )]).field2

But how about if I need to grab in a list more than one field value?

Something like:

self.env['model.name'].search([('field1', '=', 'value' )]).(field2, field3, field4)

I need to return it as a simple list to manipulate it after.

Now I' m using a ' for in' cycle (I prefer over sql, even if more simple is less secure) but I don' t like it... How about 'search_read' with domain?

Solved with:

wt = self.env['model.name']
id_needed = wt.search([('field1', '=', 'value')]).id
new = wt.browse(id_needed)
list = [new.field1, new.field2, new.field3]

Is the most efficient way I found till now. But probably I can't optimize it a little more.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Solved with:

wt = self.env['model.name']
id_needed = wt.search([('field1', '=', 'value')]).id
new = wt.browse(id_needed)
list = [new.field1, new.field2, new.field3]

This Is the most efficient way I found till now.

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

probably you can do :

for x in self.env['model_field_2'].search([('field_2/3/4_relation_to_field1,'=',value)])

อวตาร
ละทิ้ง
ผู้เขียน

field_2/3/4_relation_to_field1 is a bit confusing.

What do you mean?

u need to return field2,field3,field4 based on field1 = value right?

ผู้เขียน

Yes, but I was speaking about the syntax you use: field_2/3/4_relation_to_field1 doesn't help much. If you already tried such solution please post a real example. Thanks.

Related Posts ตอบกลับ มุมมอง กิจกรรม
7
พ.ค. 20
19050
0
มี.ค. 18
2701
0
เม.ย. 15
5376
how to use and in search? แก้ไขแล้ว
2
ธ.ค. 22
16309
0
มี.ค. 21
6649