Full Web Apps with FastAPI Transcripts
Chapter: Storing data with SQLAlchemy
Lecture: Latest release for a package

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I almost overlooked something, really quickly before we move on from the Package Details Page. Notice we were just sending this fake release back.
0:08 Let's actually rewrite this to return the real package release. Let's go down here, we'll say, create a session and we want to get the latest release,
0:17 right? And I guess there's a couple ways we could do it, we could get the package and then we could get the releases.
0:22 Or we could just do a query where the package name is something and order by release date, let's go with that one.
0:28 So we'll go to the release and we'll say filter where Release.package_id
0:34 is package_name. That should still be set as that foreign key that we're working with. And then we have the first,
0:40 that's fine, but we're also going to have, come over here, and we want to say order_by(Release.created_date.desc()).
0:50 So we want all the releases for this package order by, going the newest ones first and then just give us that. And that is going to be "release".
0:59 It could be, there's a release or there might not be a release, it might be None, hence the Optional return value here. Let's try this one more time,
1:06 make sure we're really using all the live data over there. If we go to botocore, oh yeah, look at that. It's got old snapshot data,
1:13 but there it is, botocore updates all the time so it's a little out of date, but check that out. We've got the latest release. We come back to awscli,
1:21 05-31. Ah let's good, to kombu, 05-30 and so on. Pretty cool. Now we've got that last query written and working beautifully.

Talk Python's Mastodon Michael Kennedy's Mastodon