1 00:00:00,190 --> 00:00:01,620 Now that we can follow people, 2 00:00:01,620 --> 00:00:05,120 let's update the list of posts in our stream on our own pages, so 3 00:00:05,120 --> 00:00:09,090 that we see the posts from people that we follow, and our own posts. 4 00:00:09,090 --> 00:00:12,450 We should be able to do this pretty easily by updating our get_stream method. 5 00:00:13,510 --> 00:00:17,940 So now that we have following and unfollowing users, we need to update our 6 00:00:17,940 --> 00:00:22,860 stream for a given user so that it shows the people they follow. 7 00:00:22,860 --> 00:00:27,720 So, let's go over to our models.py, go to our user model, and 8 00:00:27,720 --> 00:00:30,810 we want to look at this get_stream method. 9 00:00:30,810 --> 00:00:33,890 So right now, we just do this, Post.user is equal to self. 10 00:00:33,890 --> 00:00:35,275 So get all of my posts. 11 00:00:36,600 --> 00:00:41,530 What I wanna add into this, though, is, I wanna add in where Post.user, and 12 00:00:41,530 --> 00:00:44,580 then I'm gonna use a new selector here that we haven't seen before, 13 00:00:44,580 --> 00:00:46,470 or comparator here that we haven't seen before. 14 00:00:46,470 --> 00:00:48,390 Which is the double less than. 15 00:00:48,390 --> 00:00:53,170 And so this is for, where they are inside of another set. 16 00:00:53,170 --> 00:00:57,897 So the set that they need to be inside of is self.following. 17 00:00:59,720 --> 00:01:01,870 And then we're going to talk about that too. 18 00:01:01,870 --> 00:01:02,510 So what I'm saying is, 19 00:01:02,510 --> 00:01:08,670 find all of the posts where the Post.user is inside of the people that I follow. 20 00:01:08,670 --> 00:01:11,070 And then this right here means or, so we're saying, 21 00:01:11,070 --> 00:01:15,200 I want all the ones where I'm following them, or where they're mine. 22 00:01:15,200 --> 00:01:17,130 That's fairly straightforward. 23 00:01:17,130 --> 00:01:21,370 One other thing that I wanna add, we don't actually have to change our 24 00:01:21,370 --> 00:01:25,380 stream view for handling this new set of streams. 25 00:01:25,380 --> 00:01:27,335 We're already using get_stream. 26 00:01:27,335 --> 00:01:29,671 So the one more thing I wanna add though, 27 00:01:29,671 --> 00:01:32,440 is the ability to go look at an individual post. 28 00:01:32,440 --> 00:01:39,210 So I'm actually gonna add that here because it relates to the stream. 29 00:01:39,210 --> 00:01:41,180 And let's do post. 30 00:01:42,380 --> 00:01:45,890 And then we need to take the ID of a post, and we're gonna make that an int. 31 00:01:45,890 --> 00:01:50,060 So we'll say post_id. 32 00:01:50,060 --> 00:01:50,890 All right? 33 00:01:50,890 --> 00:01:55,700 And then view_post and it'll take a post_id. 34 00:01:55,700 --> 00:01:59,390 And so what we wanna do here is, we want to do posts 35 00:01:59,390 --> 00:02:04,691 equals models.Post.select().where 36 00:02:04,691 --> 00:02:10,210 models.Post.id is equal to the post_id that comes in. 37 00:02:10,210 --> 00:02:15,069 And then we're going to return render_template, 38 00:02:15,069 --> 00:02:19,650 stream.html, stream equals posts. 39 00:02:19,650 --> 00:02:22,400 Why didn't I do a .get on this? 40 00:02:22,400 --> 00:02:25,120 Well, I'm kind of cheating a little bit. 41 00:02:25,120 --> 00:02:29,860 What I'm doing is I'm saying, get all the posts that are, that have this id. 42 00:02:29,860 --> 00:02:32,930 And then we're gonna return the stream like normal. 43 00:02:32,930 --> 00:02:36,020 So it's this group of things. 44 00:02:36,020 --> 00:02:40,524 And so to do this, we do need to change our stream.html. 45 00:02:41,840 --> 00:02:46,060 Where we're rendering out this view, this URL here. 46 00:02:46,060 --> 00:02:52,232 What we need to do here is, we need to do url_for post, 47 00:02:52,232 --> 00:02:56,947 and post_id is going to equal post.id. 48 00:02:56,947 --> 00:02:57,823 All right. 49 00:02:57,823 --> 00:03:00,462 So now we should be able to look at two different things here. 50 00:03:00,462 --> 00:03:06,831 I'm gonna go back over to the not me account. 51 00:03:06,831 --> 00:03:07,565 Nope. 52 00:03:07,565 --> 00:03:09,905 [BLANK_AUDIO] 53 00:03:09,905 --> 00:03:11,240 What happened here? 54 00:03:13,070 --> 00:03:13,910 I made a little typo. 55 00:03:15,055 --> 00:03:16,540 Forgot to close my parentheses there. 56 00:03:18,890 --> 00:03:19,990 So let's refresh, there we go. 57 00:03:19,990 --> 00:03:24,950 So we're logged out, and we're gonna go log in as test, 58 00:03:26,800 --> 00:03:29,000 with the super secret password of password. 59 00:03:30,420 --> 00:03:34,890 If I go look at my stream, which I can get to by following. 60 00:03:34,890 --> 00:03:37,950 Then I see the kennethlove post because that was my post, and 61 00:03:37,950 --> 00:03:39,960 it's from 45 years ago, apparently. 62 00:03:39,960 --> 00:03:41,610 So, that's pretty awesome. 63 00:03:41,610 --> 00:03:42,840 What if I click on View? 64 00:03:44,470 --> 00:03:45,910 That went to new post. 65 00:03:45,910 --> 00:03:47,470 We don't need to go to new post. 66 00:03:47,470 --> 00:03:49,900 Let's see what I did wrong. 67 00:03:53,120 --> 00:03:54,595 It should be view_post. 68 00:03:57,670 --> 00:03:59,616 View_post, all right. 69 00:03:59,616 --> 00:04:02,780 Refresh this. 70 00:04:02,780 --> 00:04:03,852 I've got just that view. 71 00:04:03,852 --> 00:04:07,260 So that's pretty cool, and we've got a nice bit of, you know, 72 00:04:07,260 --> 00:04:08,310 I can go look at a post. 73 00:04:08,310 --> 00:04:12,580 I can send somebody a link, hey, you posted this thing, what was up with that? 74 00:04:12,580 --> 00:04:15,190 We got a lot of mileage out of that one small change. 75 00:04:15,190 --> 00:04:18,050 That really speaks to the power of tools like Flask and Peewee. 76 00:04:18,050 --> 00:04:20,860 And shows just how far we can go with these tools if we want to.