I am trying to show chat log in django. I can get my entire chat log in the correct order with this request.
latest_chats_list = Chat.objects.order_by('timestamp')
I want the functionality of this line (the last 10 elements are fine), but django does not allow negative indexes.
latest_chats_list = Chat.objects.order_by('timestamp')[-10:]
If I try this line, I get the messages I want, but they are in the wrong order.
latest_chats_list = Chat.objects.order_by('-timestamp')[:10]
This line gives the first 10 chats instead of the last.
latest_chats_list = Chat.objects.order_by('-timestamp')[:10].reverse()
source
share