django-db-side-computation
Installation
SKILL.md
Django DB-Side Computation
Use this skill when Django fetches rows into Python to compute values the database can compute more efficiently or more consistently.
Workflow
-
Identify the Python computation.
- Counts, sums, min/max, booleans, latest related rows, rankings, denormalized totals, or per-row derived fields.
- Confirm whether the computed value must be exact, current, and transactionally consistent.
-
Pick the SQL expression level.
filter(),exclude(), andF()for simple comparisons and updates.annotate()and aggregates for per-object counts and totals.- Filtered aggregates for conditional counts and sums.
Exists()for yes/no related-row checks.Subquery()withOuterRef()for latest or scalar related values.Window()for ranks and running calculations.GeneratedFieldfor deterministic same-row computed columns when the database supports it.