Django select max id

前端 未结 6 2133
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 03:39

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         


        
6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 03:58

    Your logic is right, this will return the max id

    res = Image.objects.filter().aggregate(max_id=Max('pk'))
    res.get('max_id')
    

提交回复
热议问题