techwithtim / Flask-Web-App-Tutorial

Code for the note storing flask web app made during a YouTube video.
932 stars 1.03k forks source link

Order by Note.date desc #85

Open vzshan opened 2 years ago

vzshan commented 2 years ago

How can we order the Notes by date in desc in view.home? Is there a better way to sort Note in current_user.Note object and return user=current_user back to home page instead.

Currently I am doing like below to return Notes object back to home age, and from home page loop Note object to get the data in desc order:-

notes=Note.query.filter_by(user_id=current_user.id).order_by(desc(Note.date))
return render_template("home.html", user=current_user, notes=notes)