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 A Social Network with Flask How to Win Friends Follow and Unfollow Buttons

Andy Hughes
Andy Hughes
8,478 Points

How to find and connect to users in a database?

In the video, we see Kenneth create follow/unfollow functions and methods. In his example you can see posts from people and choose to follow, then unfollow.

But how would it work if the follow/unfollow is not based on posts. For example, I've chosen to evolve the social app into a small student/instructor app. So if I want a bunch of students to connect to their instructor and vice-versa, how would that work do we think?

In my head, I see a class that allows for a relationship to created by an Instructor to a student. Then a function that does the same, the other way around; student to an instructor. I think I can code the relationship creation along the lines Kenneth describes.

My question though is how would the instructor identify their students?

  1. Would it be via some unique reference code (random string generator) the instructor gives to the student that they enter into a box on their profile, that then runs the relationship function and uses the unique code to create the right join?
  2. Would it be better to have a search function for the instructor to find the student and then click a 'connect' button? (Then the same for a student to find their instructor)
  3. Or could I use something clever like a QR Code that a student captures with their phone that then links to the instructor connect page via the instructors ID. (no idea how I'd physically create the right sort of link, but the concept seems cool)

Or would you do it a completely different way?

The part my brain really gets stuck on is identifying the 'other' party. It's easy to identify self, but how to find a series of students without a physical search?

Interested in thoughts before I make a decision and start breaking things :P

Andy Hughes
Andy Hughes
8,478 Points

I am leaning towards a random code generator that is unique to each instructor. The instructor would send/give the code to a potential student over email, or possibly through the app.

The student would then have a simple form page, where they enter the code and submit it.

That would then run a function that sends a message or triggers an action at the instructor's end to accept the connection. This would provide a sort of two-step authentication.

The instructor authentication would then run a function to create the relationship join.

Does that seem to be the simplest, smartest way? Thoughts?