Source: https://frameworkrecipes.dev/django/

# Django: preserve requirements through advanced agent edits

Work through Python examples of real application boundaries: Keep Django cancellation writes scoped to the authenticated tenant; Create a Django outbox event atomically with the order change. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.

[Download the Django rule pack ZIP](https://reporules.fyi/django/rule-pack.zip) · [Inspect the YAML rules](https://reporules.fyi/django/rules.yaml)

Python

## [Keep Django cancellation writes scoped to the authenticated tenant](https://frameworkrecipes.dev/django/scoped-cancellation/)

A locked row prevents concurrent state changes while this transaction decides whether cancellation is allowed. The tenant restriction belongs in the lookup that acquires the row; a lock by itself is not an access check.

Broken edit flagged · corrected edit passes

Python

## [Create a Django outbox event atomically with the order change](https://frameworkrecipes.dev/django/durable-outbox/)

An on_commit callback runs after commit but does not make message delivery durable. Store the event in the transaction and let a retrying worker publish it. Moving create outside the block makes a failed event insert leave a confirmed order without a delivery record.

Broken edit flagged · corrected edit passes

[Introductory framework example](https://frameworkrecipes.dev/django/intro/)

## Use a correction as a saved requirement

Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.

Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.

[Official Django documentation](https://docs.djangoproject.com/) · [All language and framework recipes](https://frameworkrecipes.dev/)

**Framework Recipes**

Implementation, failure path, check.

Published by Perch · © 2026 Verglas LLC. Framework Recipes is a Perch publication.

Perch’s MIT license covers the CLI; hosted model analysis is a paid service. Relevant source is sent to the configured model service.

[Perch CLI MIT license](https://github.com/lakeday-org/perch/blob/main/LICENSE) · [Article text](https://frameworkrecipes.dev/django/index.md) · [Resource index](https://frameworkrecipes.dev/llms.txt)
