django-discipline
Skill4 starsChanged 9 months agoUnlicenseView on GitHub
Use whenever creating, modifying, or fixing any code in a Django project — a project with manage.py present or django in pyproject.toml/requirements.txt. Applies to every change in such a project, whether or not the change looks Django-specific. This is the discipline skill — for framework pattern lookups, use django instead.
In this repository70 other files it gives its agents.
- agent/AGENTS.mdAGENTS.md
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- git-guardrails-claude-codeSkill
- setup-project-skillsSkill
- skill-creatorSkill
- websearchSkill
- writing-great-skillsSkill
- codebase-designSkill
- construction-craftSkill
- critical-partnerSkill
- data-intensiveSkill
- diagnosing-bugsSkill
- docker-disciplineSkill
- documentation-lifecycleSkill
- domain-driven-designSkill
- enterprise-patternsSkill
- git-disciplineSkill
- legacy-codeSkill
- production-readinessSkill
- refactoring-passSkill
- resolving-merge-conflictsSkill
- tddSkill
- testing-workflowSkill
- ui-design-directionSkill
- webapp-testingSkill
- django-allauthSkill
- djangoSkill
- dockerSkill
- drfSkill
- full-calendarSkill
- giteaSkill
- htmxSkill
- http-status-codesSkill
- hyperscriptSkill
- langchainSkill
- litestarSkill
- prestashopSkill
- pykeSkill
- python-asyncSkill
- tablerSkill
- cleanroom-rewriteSkill
- councilSkill
- court-jesterSkill
- domain-modelingSkill
- fix-prSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- humanifySkill
- implementSkill
- implement-specSkill
- improve-codebase-architectureSkill
- ponytail-auditSkill
- ponytail-debtSkill
- prototypeSkill
- qaSkill
- researchSkill
- restore-test-pyramidSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
26 rules. About 0 are common, 10 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 37
When either is true, this checklist applies to all code you write or modify.
- Distinctive: line 41
Follow these in order. Every item is mandatory.
- Very specific: line 49
NEVER: write migration files by hand unless you need RunPython, RunSQL, or custom AlterField with data transforms.
- Very specific: line 50
If you need RunPython/RunSQL: run makemigrations first to get the skeleton, then inject your custom code into the generated file.
- Very specific: line 51
After creating migrations, verify with python manage.py migrate --check (or run migrations if the project is set up for it).
- Very specific: line 52
If makemigrations detects no changes but you modified a model, stop and investigate — your model change may not be registered.
- Distinctive: line 60
Run this after every code change, before any manual lint cleanup.
- Distinctive: line 61
Only fix what ruff can't auto-fix yourself.
- Very specific: line 62
Do NOT run isort, black, flake8, or autoflake separately — ruff subsumes all of them.
- Distinctive: line 63
Do NOT manually remove unused imports, fix formatting, or sort imports that ruff handles.
- Very specific: line 67
ForeignKey / OneToOne: always use .select_related("field")
- Very specific: line 68
ManyToMany / reverse FK: always use .prefetch_related("field")
- Very specific: line 69
M2M or reverse FK filtering: always append .distinct() to avoid duplicate rows
- Very specific: line 84
Import from the public interface: from apps.context import Symbol
- Very specific: line 85
Never: import from internal modules: from apps.context.models import Symbol
- Distinctive: line 90
Before renaming any model field:
- Distinctive: line 92
Update all references, not just the model definition
- Very specific: line 93
Run makemigrations after the rename
- Very specific: line 97
Use update_or_create() in test fixtures to avoid unique constraint violations
- Very specific: line 98
Use Sequence for unique fields in tests, not django_get_or_create
- Very specific: line 104
If using WhiteNoise: WhiteNoiseMiddleware must be second in MIDDLEWARE, directly after SecurityMiddleware.
- Distinctive: line 114
Every item in the checklist traces to a real production bug.
- Distinctive: line 126
If it points at production settings, tests hit production CSP, CSRF middleware, and database — causing auth failures, origin-check errors, …
- Very specific: line 129
Add http://127.0.0.1 to CSRF_TRUSTED_ORIGINS and ALLOWED_HOSTS
- Distinctive: line 131
Use SQLite in-memory or temp file
- Very specific: line 134
Run pytest --collect-only to verify the correct settings module loads before committing to a full test run.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Django Discipline
STOP — Read This Before Writing Any Django Code
This skill is mandatory for all Django project work. If you are about to create, modify, or fix code in a Django project — stop here and follow this checklist. These rules exist because agents consistently get them wrong.
You are rationalizing if you think:
| Excuse | Reality |
| "I'll just write the migration quickly by hand" | Manual migrations miss dependency chains and break migration graphs. Run makemigrations first. |
| "I'll fix the lint issues manually" | ruff check --fix handles 90% of lint issues in one shot. Run it before manual cleanup. |
| "I know Django, I don't need this" | That's exactly the attitude that produces N+1 queries and broken migration chains. Follow the checklist. |
"This is a simple model change, no need for makemigrations" | There is no simple model change. Run makemigrations. Always. |
"I'll add select_related later if it's slow" | You won't. The N+1 ships to production. Add it now. |
Detection
You are in a Django project if:
manage.pyexists in the project root, ORpyproject.toml/requirements.txtcontainsdjango
When either is true, this checklist applies to all code you write or modify.
Django Workflow Checklist
Follow these in order. Every item is mandatory.
1. Migrations — Always Auto-Generate First
python manage.py makemigrations- NEVER write migration files by hand unless you need
RunPython,RunSQL, or customAlterFieldwith data transforms. - If you need
RunPython/RunSQL: runmakemigrationsfirst to get the skeleton, then inject your custom code into the generated file. - After creating migrations, verify with
python manage.py migrate --check(or run migrations if the project is set up for it). - If
makemigrationsdetects no changes but you modified a model, stop and investigate — your model change may not be registered.
2. Linting — Ruff Before Manual Cleanup
ruff check --fix && ruff format- Run this after every code change, before any manual lint cleanup.
- Only fix what ruff can't auto-fix yourself.
- Do NOT run
isort,black,flake8, orautoflakeseparately — ruff subsumes all of them. - Do NOT manually remove unused imports, fix formatting, or sort imports that ruff handles.
3. ORM — Prevent N+1 Queries
- ForeignKey / OneToOne: always use
.select_related("field") - ManyToMany / reverse FK: always use
.prefetch_related("field") - M2M or reverse FK filtering: always append
.distinct()to avoid duplicate rows - Never access related objects in a loop without eager loading
# ❌ Bad: N+1 queries
for order in Order.objects.all():
print(order.user.email)
# ✅ Good: single query with join
for order in Order.objects.select_related("user"):
print(order.user.email)4. Imports — Public API Only
- Import from the public interface:
from apps.context import Symbol - Never import from internal modules:
from apps.context.models import Symbol - For circular imports: use deferred imports inside functions with
# Circular import: <reason>comment, or PEP 562 lazy__getattr__in__init__.py
5. Model Changes — Grep Before Renaming
Before renaming any model field:
- Grep the entire codebase for the field name: views, serializers, forms, templates, test fixtures, factories, admin, services
- Update all references, not just the model definition
- Run
makemigrationsafter the rename
6. Testing — Django-Specific Patterns
- Use
update_or_create()in test fixtures to avoid unique constraint violations - Use
Sequencefor unique fields in tests, notdjango_get_or_create - Prefix test-only settings with
TEST_to avoid collisions with seed/migration data - For E2E tests: navigate via UI clicks, not
page.goto(url)
7. Settings — WhiteNoise Ordering
If using WhiteNoise: WhiteNoiseMiddleware must be second in MIDDLEWARE, directly after SecurityMiddleware.
Adjacent Tools
- DRF: Load the
drfskill for API patterns - django-debug-toolbar: Dev-only. Never ship to production. Verify
INTERNAL_IPSis set. - Reference patterns (model fields, views, templates, forms, admin, auth, middleware): Load the
djangoskill
Enforcement
Every item in the checklist traces to a real production bug. If you skip a step, you are introducing risk that has already bitten this project. Follow the checklist.
pytest Settings Module Verification
Before running pytest, verify the pytest config (pyproject.toml / pytest.ini / setup.cfg) points DJANGO_SETTINGS_MODULE at the project's dedicated test settings module — whatever the project names it — never at the production/default settings:
# pyproject.toml
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "<project>.settings_test" # never the production settings moduleIf it points at production settings, tests hit production CSP, CSRF middleware, and database — causing auth failures, origin-check errors, and data pollution. Test settings must:
- Disable/remove CSRF middleware (
CsrfViewMiddleware) - Add
http://127.0.0.1toCSRF_TRUSTED_ORIGINSandALLOWED_HOSTS - Relax CSP directives for test environment
- Use SQLite in-memory or temp file
- Set
DEBUG = True(allows CSRF middleware to bypass origin check)
Run pytest --collect-only to verify the correct settings module loads before committing to a full test run.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

