Django ORM 6.0
Last reviewed Sep 25, 2026
Prompt Details
Prompt Composition
3prompts
- Python 3155 lines · 3.8K tokens
- Django 6.0110 lines · 4.1K tokens
- Django ORM 6.071 lines · 3.4K tokens
Total336 lines · 11.3K tokens
CWE Coverage
- 20
- 23
- 36
- 59
- 73
- 78
- 79
- 89
- 95
- 117
- 201
- 203
- 208
- 209
- 214
- 250
- 287
- 295
- 307
- 319
- 328
- 338
- 347
- 352
- 362
- 367
- 379
- 384
- 409
- 416
- 426
- 427
- 434
- 470
- 502
- 521
- 524
- 532
- 601
- 611
- 614
- 639
- 640
- 674
- 732
- 770
- 772
- 776
- 778
- 798
- 807
- 829
- 862
- 863
- 915
- 916
- 918
- 942
- 1004
- 1021
- 1104
- 1275
- 1333
- 1336
- 1395
Prompt Preview
Apply the Django 6.0 prompt first. These additional rules cover Django ORM 6.0.8 on Python 3.12–3.14, including query scope, related objects, write paths, constraints, transactions, database routing, and migrations. Apply them to synchronous and asynchronous ORM entry points.
Query construction and projections
- Map external filter, sort, projection, relation, and aggregation choices to fixed field paths, lookup operators, expressions, and aliases. Never expand request dictionaries directly into
Q(),filter(),annotate(), oralias(); parameterized values do not authorize access through arbitrary lookup paths. - Keep custom
Lookup.as_sql()and expressionas_sql()implementations parameterized: compile child expressions with the supplied compiler and return SQL plus a tuple of parameters, as required by Django 6.0. Do not interpolate child values into SQL to work around parameter-list incompatibilities. - Put tenant and permission predicates inside each raw statement, including SQL passed to
raw()on a previously filtered QuerySet;raw()starts a new query and discards that filtering. Review raw subqueries for their own scope. - Bound raw-query results in SQL; slicing or indexing a
RawQuerySetdoes not add a database-level limit. On MySQL, validate parameter types before raw comparisons because implicit numeric coercion can change which text values match. - Use explicit approved fields for
values()and response serialization. Treatonly()anddefer()as loading optimizations: accessing an omitted model field can fetch it later, so neither API