Lesson 17 — Relations
Records that point to other records
A foreign key is a field that stores the id of a record in another table. An order does not copy the user's name; it stores uid: 1, and you look up user 1 when you need the name. In Django: order.user.name.
cities = {7: "Almaty"}
cities[shop["city_id"]] # 'Almaty'
Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.
Why it matters: storing the name once means changing it once — every order shows the new name.
Print each order as "<user name> paid <amount>", looking the name up by uid.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Django Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Django Foundations books — check the publication year so the examples match current versions.
Search Amazon →