Model relationships preview
📖 Scenario: You are building a simple Django app to manage books and their authors. Each book has one author, and each author can have multiple books.
🎯 Goal: Create two Django models, Author and Book, with a one-to-many relationship. Then, write a query to get all books by a specific author.
📋 What You'll Learn
Create an
Author model with a name fieldCreate a
Book model with a title field and a foreign key to AuthorCreate a variable
author_name with the value 'Jane Austen'Write a Django ORM query to get all books by the author with name
author_name💡 Why This Matters
🌍 Real World
Managing related data like authors and books is common in library or bookstore apps.
💼 Career
Understanding model relationships and queries is essential for backend Django development.
Progress0 / 4 steps