The newsroom and the method
Meet the single Django 6.1.3 application this book measures, and see how live recordings, AST source pointers, and plates work.
Toy single-model snippets hide the mechanisms that break real projects. A one-table blog never exercises cross-app foreign keys during startup, never hits multi-valued join promotion across an explicit many-to-many through table, never feels the memory difference of deferring a large TextField, and never forces ModelAdmin to coordinate parent validation alongside inline formsets inside one transaction.
Every trace, SQL recording, and benchmark in this book therefore runs against one small, realistic Django 6.1.3 application: desk, a miniature newspaper edition desk built in the spirit of the Lawrence Journal-World where Django began. Every recording boots that project against an in-memory SQLite database seeded with fixed UTC timestamps anchored to "2026-11-25", so primary keys, query counts, SQL parameters, and rendered byte counts stay reproducible from chapter to chapter.
A live census of the booted project
Booting the newsroom project and asking Django’s own app registry, database introspection backend, and root URLResolver what exists produces this census:
Live census of the booted desk/ project
installed_apps=8 middleware=8 registered_models=15 db_tables=18 root_url_patterns=6
seeded rows: desks=3 reporters=4 beats=3 editions=2 stories=6 (published=5) story_beats=8 corrections=3 subscriptions=3
Look closely at one small arithmetic puzzle on the very first line: registered_models=15, yet db_tables=18. Why are there three more tables in SQLite than models returned by Apps.get_models?
The answer previews two pieces of ORM machinery we will open in Part II. First, Apps.get_models excludes auto-created intermediate tables by default (include_auto_created=False): Django’s built-in auth models silently generated three many-to-many join tables ("Group_permissions", "User_groups", and "User_user_permissions"). Second, our newsroom app declares one proxy model (PublishedStory) that adds a custom manager without creating a database table (-1). Third, the migrations framework creates its own "django_migrations" bookkeeping table (+1). Put them together: 15 - 1 + 3 + 1 = 18 tables.
The schema and request surface
The project splits across two applications — Newsroom and Subscribers — specifically so cross-app model references, migrations, and transactions behave as they do in a real codebase.
# Models in desk/newsroom/models.py and desk/subscribers/models.py
Desk # 3 sections: Metro, City Hall, Sports
Reporter # 4 journalists (Ada, Bram, Cora, Dag); FK -> Desk, optional OneToOne -> User
Beat # 3 topic beats: Transit, Budget, Housing
Edition # 2 daily editions: 2026-11-24 (Tuesday Final), 2026-11-25 (Wednesday Final)
Story # 6 stories (5 published, 1 draft); TextField body; FKs -> Desk, Reporter, Edition;
# M2M beats through StoryBeat (primary flag and position ordering)
Correction # 3 child rows pointing to Story (prefetch_related, cascade Collector, Admin inline)
PublishedStory # proxy model over Story with a custom manager filtering status="published"
Subscription # 3 reader subscriptions in subscribers with a cross-app FK -> "newsroom.Desk"
Six root URL patterns cover every request dispatch path we measure across the book:
| Route | View | What later chapters measure here |
|---|---|---|
"/" |
View Edition front | What later chapters measure here Plain synchronous function-based view |
"/ |
View Edition list | What later chapters measure here Generic ListView with Query and Query |
"/ |
View Story detail | What later chapters measure here Generic DetailView resolving M2M through rows and child corrections |
"/submit/" |
View Story submit | What later chapters measure here ModelForm cleaning, CSRF checks, django, and django |
"/wire/status/" |
View Live wire status | What later chapters measure here Pure coroutine view using async ORM (QuerySet.acount, QuerySet.afirst) |
"/admin/" |
View AdminSite |
What later chapters measure here Registered ModelAdmin with TabularInline formsets for beats and corrections |
Outside the views themselves, two middleware classes — a synchronous timing header wrapper and a pure-async audit wrapper — sit alongside Django’s standard security, session, CSRF, and authentication middleware. Newsroom connects a synchronous post_save signal receiver inside its AppConfig.ready hook, and defines a Django 6.1 background task for building an edition digest.
Reading the evidence
Every file of this newsroom project is published as plain text under "/desk/", and every dark console exhibit across the book links straight to its full raw output and the runnable script that produced it — with SQL lines set in Press Brass so database wire traffic separates visually from Python calls, and "TRAP" lines set in Crimson where an abstraction silently leaks. Every backticked Django identifier is verified against the pinned Django 6.1.3 source tree, and margin pointers link straight to the exact lines of code where the mechanism lives.
Before WSGIHandler could handle that Wednesday edition request, however, Django had to boot: load settings without crashing on early imports, discover eight apps, register every model, wire cross-app foreign keys without circular-import deadlocks, and run every ready hook. That startup machinery is where Booting Django begins.