I am building my first Django program from scratch and am running into troubles trying to print out items to the screen from newest to oldest. My model has an auto date time fie
By the way you also have Django's created_at
field at your disposal:
ordered_tasks = TaskItem.objects.order_by('-created_at')
ordered_tasks = TaskItem.objects.order_by('-created_date')
The order_by()
method is used to order a queryset. It takes one argument, the attribute by which the queryset will be ordered. Prefixing this key with a -
sorts in reverse order.