Django select max id

Posted by pistacchio on Stack Overflow See other posts from Stack Overflow or by pistacchio
Published on 2010-05-21T18:19:00Z Indexed on 2010/05/21 19:30 UTC
Read the original article Hit count: 385

Filed under:
|

Hi,

given a standard model (called Image) with an autoset 'id', how do I get the max id?

So far I've tried:

max_id = Image.objects.all().aggregate(Max('id'))

but I get a 'id__max' Key error.

Trying

max_id = Image.objects.order_by('id')[0].id

gives a 'argument 2 to map() must support iteration' exception

Any help?

© Stack Overflow or respective owner

Related posts about django

Related posts about python