Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Move Django performance-sensitive Python loops into database-side computation with annotations, aggregates, filtered aggregates, F expressions, functions, Subquery, OuterRef, Exists, Window expressions, db_default, and GeneratedField. Use when Django code counts, sums, filters, flags, ranks, or derives values in Python after fetching rows.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 88% | 0% |
| case-21 | ✗→✓ | ▲ Improved | 3% | 0% |
| case-20 | ✗→✓ | ▲ Improved | -29% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 3% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 22% | 0% |
Use this skill when Django fetches rows into Python to compute values the database can compute more efficiently or more consistently.
filter(), exclude(), and F() for simple comparisons and updates.annotate() and aggregates for per-object counts and totals.Exists() for yes/no related-row checks.Subquery() with OuterRef() for latest or scalar related values.Window() for ranks and running calculations.GeneratedField for deterministic same-row computed columns when the database supports it.QuerySet.explain().See aggregation-patterns.md for Django expression examples.
Compare correctness against the old Python calculation on representative data, then measure SQL time and total response time.
Other measured skills in the registry, with their headline benchmark lift.