技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
django-db-side-computation【数据与研究】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.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this skill when Django fetches rows into Python to compute values the database can compute more efficiently or more consistently.
Identify the Python computation.
Pick the SQL expression level.
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.Validate query shape.
QuerySet.explain().Decide whether the result should be stored.
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.