django queryset last 10 1

django queryset last 10

last_ten = Messages.objects.filter(since=since).order_by('-id')[:10]
last_ten_in_ascending_order = reversed(last_ten)

Here is what the above code is Doing:
1. We’re getting the last 10 messages from the database.
2. We’re reversing the order of the messages so that the most recent message is first.
3. We’re passing the messages to the template.

Similar Posts