1

I've created a budget app that lists your income and expenses. And instead of listing most recent evemts at the top it lists them in the bottom. Is there anyway I could reverse the list or sort by most recent?

Here are some of my folders and my django project. Let me know if I need to add any others, I'm a beginner.

HTML file

Views

Models

Django Project, as you can see the most recent are at the bottom

  • 4
    Does this answer your question? [django order\_by query set, ascending and descending](https://stackoverflow.com/questions/9834038/django-order-by-query-set-ascending-and-descending) – Nicolae Jun 08 '20 at 19:56

1 Answers1

2

You can use order_by() on your queryset. So it would be like this

payment = Payment.objects.order_by("-date_created")

Notice the presence of "-" in arguments, which implies descending order and otherwise ascending order. You call also use .desc()

Nicolae
  • 432
  • 5
  • 13