Building data-driven web apps with Flask and SQLAlchemy Transcripts
Chapter: Using SQLAchemy
Lecture: Concept: Ordering data
0:00 Databases are really good at filtering and ordering.
0:03 Here is a function, find_all_packages
0:05 and the idea is I would like, ideally
0:07 a list of all the packages in the database
0:10 showing the newest ones first and the oldest ones last.
0:13 So we're going to do a query on package
0:15 and we don't do any filtering
0:16 because like we said the in name, we want them all.
0:19 But we are going do an order_by
0:21 so we say, query of package.order_by
0:24 and then we always express these
0:25 operations in terms of the type, so package.created
0:29 If we just said package.created
0:30 it would order ascending by the created_date
0:33 but we want descending, so we go into that descriptor
0:37 created and we say .desc we call the function
0:39 to reverse the sort, and then we just say
0:42 give us all the packages, here they come.