Django's GeneratedField
summary
GeneratedField lands in Django 5.0 and computes column values in the database using SQL expressions, with concrete examples on SQLite and PostgreSQL: geometry via GeoDjango (hash, geojson, length km, polygon area), JSON extraction from PyPI metadata, concatenation and JSON object construction, and full‑text vectors with language fallbacks. Migrations show SQL, store vs virtual differs by DB, constraints force immutable expressions, and must refresh_from_db to see updated values; performance tests report milliseconds on 1k–10k packages.
AI-written summary · about
chapters (13)
- 0:00GeneratedField introduction
- 10:15What GeneratedField is
- 11:58Area of circle with SQLite
- 14:13Item price with quantity
- 16:00Traffic light state machine
- 19:56PostgreSQL and JSON data
- 23:34Names to full names and JSON
- 25:44Full text search vectors
- 29:22Date range for bookings
- 30:27GeoDjango geospatial data
- 32:35Line length in routes
- 33:18Polygon area for boundaries
- 34:01Closing remarks
related talks
26mPostgreSQL Generated Columns by Example
27mDjango - Customise your SQL
21mDjango and PostgreSQL: An Even-Closer Union
23mDjango with PostgreSQL superpowers
25mBuilding effective Django queries with expressions
18mUnleash the power of Generated/Virtual Columns in MySQL
22mDjango with PostgreSQL superpowers
43mDigging Into Django's Migrations
