Set Up the Foreign Key
Understand how to establish foreign key relationships between listings and users in Django. This lesson guides you through updating models and views, applying migrations, and testing the setup to ensure each listing is properly assigned to its creator.
We'll cover the following...
We'll cover the following...
The listings on the website are not tied to any users yet. Users don’t want to see other peoples’ listings, so we’ll use a foreign key to keep track of which users created which listings.
A foreign key is a way to create a relationship in a model. In our case, the relationship is between the listings and the users. Each listing will belong to a specific user who created the listing.
Listings linked to a user