Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Using SQLAchemy
Lecture: Concept: Ordering data

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Databases are really good at filtering and ordering. Here's a function, find_all_packages and the idea is I would like really
0:08 a list of all the packages in the database showing the newest ones first and the oldest ones last. So we're going to do a query on package
0:16 and we don't do any filtering 'cause you know, we said in the name, we want them all but we are going to do an order by.
0:22 So we say query a package.orderby and then we always express these operations in terms of the type, so package.created.
0:30 And if we just said package, dot, created it would order ascending by the created date but we want descending, so we go to that descriptor created
0:38 and we say, .desc, we call the function to reverse the sort and then we just say give us all the packages, here they come.


Talk Python's Mastodon Michael Kennedy's Mastodon