Lesson 2 — Modelling data
Models are classes
In Django, a model describes one kind of thing your site stores — a product, a user, a post. A model is a Python class: a blueprint, and each object made from it is one record. The __init__ method runs when you create an object and saves the values on self.
# real Django: class Product(models.Model): name = models.CharField(...)
p = Product("Book", 20)
print(p.name) # Book
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: models are the heart of every Django app — the database tables are generated from them.
Add a stock attribute to Product (third argument), then print the name, price and stock of the book.
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.