简体   繁体   中英

Django ORM Query , how to convert the query set to tuple of tuples

I'm trying to do this from query

(('1','A'), ('2','B'), ....)

to use it as choice field in my form, how to convert my query result to do this ?

where 1,2 is the row id and A,B is another columns value

many thanks

I found the answer here but I change simple thing

[(q['x'], q['y']) for q in query]

to

tuple((q['x'], q['y']) for q in query)

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