Live Link: Flybook
Flybook, a pixel perfect Facebook clone, is a popular social media website that allows users to publicly share profile, share posts, leave comments, and add other users as friends.
Before you begin, please check the following Wiki documents:
- Python
- Flask
- SQLAlchemy
- PostgreSQL
- Docker
wtforms,wtforms validators
- React.js
- Redux
- JavaScript
- HTML, Vanilla CSS
- Heroku (for hosting services)
- AWS (photo bucket)
- Material UI Icons
react-icons,date-fns
- These code shows how to correctly determine the join condition between parent/child tables when having multiple foreign keys that are referencing the same table. In this case, the Post model below have two foreign keys
user_idandwall_idthat are pointing to theusers.idin the User model. By explicitly addingforeign_keysargument on both relationships will help SQLAlchemy know how to handle these conditions and not throw anAmbiguousForeignKeysError.
app/models/user.py
post_sender = db.relationship(
'Post',
back_populates='post_user_id',
foreign_keys=Post.user_id,
cascade='all, delete-orphan'
)
post_receiver = db.relationship(
'Post',
back_populates='post_wall_id',
foreign_keys=Post.wall_id,
cascade='all, delete-orphan'
)app/models/post.py
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
wall_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
post_user_id = db.relationship(
'User',
back_populates='post_sender',
foreign_keys=user_id
)
post_wall_id = db.relationship(
'User',
back_populates='post_receiver',
foreign_keys=wall_id
)- When a user activates the search bar, the search dropdown will show. Based on the search input values, the
handleSearch()function is invoked when anonChange()event occurs. It uses.filter()to iterate through the channels and dynamically displays and returns what matches the search input value. When a user clicks on the search result, they will be redirected to the user profile.
react-app/src/components/NavBar.js
const handleSearch = (e) => {
if (e.target.value === "") {
setSearchInput("");
setSearchResults([]);
};
if (e.target.value.length > 0) {
let filteredResults = Object.values(users).filter(user =>
user['firstname']?.toLowerCase().includes(e.target.value.toLowerCase())
|| user['lastname']?.toLowerCase().includes(e.target.value.toLowerCase())
);
setSearchInput(e.target.value);
setSearchResults(filteredResults);
};
};- My biggest challenge was getting an
AmbiguousForeignKeysErrorby not setting the proper foreign key relationship between User and Post models. In the Post model, I have two foreign keysuser_idandwall_idthat are both referencing theusers.idin the User model. After parsing through SQLAlchemy documentation, I was able to setup the proper relationship by explicitly addingforeign_keysargument on both models and correctly determined the join condition between parent/child tables. See code snippet above.
- Friend Requests
- Notifications
- Dark mode
- Responsive design
© 2021 Flybook. No rights reserved.

