UNIT 05 · TOPIC 05
Django Models
A Django model defines application data as a Python class and can create database tables through migrations.
The idea
Django Models, simply explained
A Django model defines application data as a Python class and can create database tables through migrations.
01
See the big picture
How the idea flows
Read the diagram as a simple path: begin with a problem, use the Python idea, then verify the result.
02
Everyday connection
Real-life example
↗
A Course model records the title and duration for every class on a training website.
03
Learn by doing
Python code example
PYTHONExample
from django.db import models
class Course(models.Model):
title = models.CharField(max_length=120)
duration_weeks = models.PositiveIntegerField()Expected result
Django can create a Course database tableTry it: Change one value in the code, predict what will happen, then run it and compare your answer.
04
Keep this in mind
Key takeaways
- A Django model defines application data as a Python class and can create database tables through migrations.
- Think of a real problem where django models could save time or organize information.
- Test small changes and read the result carefully before moving to a bigger program.
Quick self-check
Can you explain it in your own words?
What is the main idea of Django Models?
A Django model defines application data as a Python class and can create database tables through migrations.
Where could you see this idea in everyday life?
A Course model records the title and duration for every class on a training website.
