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 trial

Python Build a Social Network with Flask How to Win Friends Follow and Unfollow Buttons

How to add "accept follow" or "decline follow" to this app?

Let's say till we developed programming for follow button and start follow. But what if there would accept and decline "follow": Example: "User A" clicks on follow button on "User B", Now "User B" should get an notification that "accept or decline 'User A' ": If "User B" declines "User A", "User A" cannot follow "User B" & vice versa for accept too.

Thanks for showing such intense tutorial, but need these feature as it's common on social network which you must maintain.

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

As to your request as to how to create an accept or decline approval of follow request, the information in the video can be extrapolated to create it. One organization is discussed below. As you read down the new elements, you can see that the details get finer and finer. It's up to you how far to go. The list may not be exhaustive, but does cover the major elements.

  • Add a new model called FollowRequest that models the request to form a Relationship. With similar from_user and to_user attributes. Plus a declined attribute, initially False
  • Add new function request_to_follow that creates new FollowRequest instance. This function is triggured by the follow button
  • Add search to a user's home view that displays any FollowRequest.to_user matching their User. If present, display appropriate approve and decline buttons for each FollowRequest
  • Add search to a user's home view that displays any FollowRequest.from_user matching their User. These are requests they have made to follow. If declined is False then display waiting approval. If declined is True then display declined.
  • The approve button calls the existing follow function.
  • Add new function decline_to_follow that changes the value FollowRequest.declined to True.
  • The decline button calls decline_to_follow
  • If FollowRequest.declined is True, disable the follow button display
  • If declined follow requests cause the reverse request to be disabled, create new FollowRequest instance with the from_user and to_user reversed and declined initiated to True

As you can see from the above list, As each feature or branch is added to the relationships between users, the amount of overhead and functionality can grown quite rapidly. This is why the course didn't delve into this extra details. There are no new programming techniques needed in the above list, but rather an exercise in planning out the architectural changes.

I hoped this helped. Post back if you need more help. Good luck!!

This would be really helpful to me. Thanks alot, Cris Freeman! That's why "TreeHouse team" rocks! One thing is that your 'TREEHOUSE' User Interface is awesome - it's so simple & perfect.