Reputation: 1035
I tried to get the latest id in Django but get the error.
def getlatestid(request):
cot_info = COT.objects.latest('id')
return JsonResponse({"data": list(cot_info)})
TypeError: 'COT' object is not iterable
Upvotes: 0
Views: 68
Reputation: 51968
latest(...)
returns an object, not a list. So, you can try like this to fix the error:
def getlatestid(request):
cot_info = COT.objects.values().latest('id')
return JsonResponse({"data": cot_info})
Upvotes: 2