django convert list of objects to list of primary keys

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-05-06T10:19:04Z Indexed on 2010/05/06 10:28 UTC
Read the original article Hit count: 136

Filed under:

Hi,

As the title says I have a list of Django objects and I want to get a list of primary keys. What is the best way of doing this?

I know I could do

my_list = []
for item in object_list:
    my_list.append(item.pk)

but was wondering if there is Django or Python specific way of doing this better.

Thanks

© Stack Overflow or respective owner

Related posts about django