简体   繁体   中英

Retrieve "id" as list from browse record of many2many field?

I want to extract id from the browse record in to a list.

user_obj = self.pool.get('res.users') 
user_values = user_obj.browse(cr, uid, uid)
print user_values.company_ids

is [browse_record(res.company, 36), browse_record(res.company, 30)]

I tried br_record.company_ids[0][1]

I want a id's in a list_id = [36, 30]

br_record is a list so you need to index into it.
Indexing into br_record returns a browse_record .
I'm assuming browse_record has an id field.

So to access a single record:

br_record[0].id == 36

To construct the list of ids you can use a list comprehension:

list_id = [br.id for br in user_obj.browse(cr, uid, uid).company_ids]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM