Create One To Many Database Relationship - Flask Fridays #28

Codemy.com September 24, 2021
Video Thumbnail
John Elder Logo

John Elder

@johnelderai

About

AI is taking over the world...let's get into it! OpenClaw, Claude Code, Manus, Perplexity, and whatever other weird AI stuff that comes along with a pinch of Python Programming thrown in from time to time. Check out my website JohnElder.AI and Codemy.com for more videos!

Video Description

In this video we'll create a foreign key with a one to many relationship so that we can link our posts to users. We want to allow users to have many posts, but posts to have just one user. So we'll create a relationship in our models to reflect that. #flask #codemy #JohnElder Timecodes 0:00​​ - Introduction 0:50 - Delete Posts and Users 1:55 - Create Foreign Key To Link Users 4:15 - Create One To Many posts Relationship 6:34 - Put users.id in Quotation Marks 6:44 - Make Migration and Migrate Database 7:05 - Add Users 7:41 - Remove Author Field from Add_post Page 8:08 - Modify Add_Post Function Add User ID 9:22 - Remove Author Validator From WebForm 9:40 - Modify Posts Page To Add User's Name 10:47 - Update Singular Post Page 11:03 - Modify Edit Post Page and Function 12:54 - Conclusion