Django date query from newest to oldest

后端 未结 2 1619
北恋
北恋 2021-02-19 09:27

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

2条回答
  •  鱼传尺愫
    2021-02-19 09:52

    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.

提交回复
热议问题