Maru Kun

77%
Flag icon
To get data through a foreign key relationship, you use the lowercase name of the related model followed by an underscore and the word set ➊. For example, say you have the models Pizza and Topping, and Topping is related to Pizza through a foreign key. If your object is called my_pizza, representing a single pizza, you can get all of the pizza’s toppings using the code my_pizza.topping_set.all().
Python Crash Course: A Hands-On, Project-Based Introduction to Programming
Rate this book
Clear rating