Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoseph Banks
5,070 Pointsuser.posts vs. user.get_stream()
Why are two different approaches used to get the user's posts in this video? For the current user, the method, get_stream(), is used and for all other users, the posts attribute is used.
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsIt comes down to convenience. In the User
model there are get_posts()
and get_stream()
methods. The former returns just this user's posts and the latter return this user's post plus the posts of those being followed.
So the more direct question might be why user.posts
vs. user.get_posts()
? It comes down to the desire to limit the number off posts to 100. Since the get_posts()
method didn't have a way to limit the number of returned posts, Kenneth chose to used the direct coding method of user.posts.limit(100)
vs. rewriting the method in the User
model.
All three get_posts()
, get_stream()
and current_user.get_stream().limit(100)
all return a queryset of posts. The difference only being which set of posts are return.