AgentLint Verified 100/100Verified Framework Starter (Python 929-repo corpus)

    Django (Python) CLAUDE.md & AGENTS.md Template

    Migration safety, N+1 query prevention, DRF serializer guards, and fast targeted manage.py / pytest runs.

    # Django Project — Django Harness
    
    Django 5 + Python 3.12 web application with PostgreSQL, pytest-django, Ruff, and explicit migration checks.
    
    ## Commands
    
    - Sync deps: `uv sync --dev`
    - Fast targeted test: `uv run pytest apps/orders/tests/test_views.py -x -q --reuse-db`
    - Full suite: `uv run pytest -q`
    - Migration drift check: `uv run python manage.py makemigrations --check --dry-run`
    - Lint & system check: `uv run ruff check . && uv run python manage.py check`
    
    ## Rules
    
    - Don't modify committed migration files in `*/migrations/`. Instead generate a new forward migration with `uv run python manage.py makemigrations`. Because mutating applied migrations breaks staging and production databases.
    - Don't use `fields = "__all__"` on ModelForms or DRF serializers. Instead list allowed fields explicitly. Because wildcard exposure allows mass-assignment of staff or billing flags.
    - Don't run database queries inside template loops or serializer `SerializerMethodField` without `select_related` / `prefetch_related`. Because N+1 queries degrade page latency under load.
    - When adding new apps or auth permissions, read `docs/django-conventions.md` first.
    
    ## Continuity & Safety
    
    - Keep `.env`, `db.sqlite3`, and `CLAUDE.local.md` out of git — never hardcode `SECRET_KEY`.
    - Record migration numbers and passing test outputs in `HANDOFF.md`.

    Most Adopted Django (Python) Rules Across Real Open-Source Repos

    Adoption benchmarks measured in the parent language cohort of our 4,533-repo harness study, paired with framework-specific invariants:

    pytesttesting

    pytest-django targeted test runs (929 Python corpus repos)

    45.9%426 repos
    unit-teststesting

    Model, view, and serializer unit tests (929 Python corpus repos)

    40.9%380 repos
    error-handlingpatterns

    Explicit transaction and error boundaries (929 Python corpus repos)

    30.4%282 repos
    rufftooling

    Ruff lint and formatting (929 Python corpus repos)

    29.1%270 repos
    dockertooling

    Dockerized Django + Postgres local stack (929 Python corpus repos)

    28.6%266 repos
    Essential Commands (Checks W1 & W7)
    install
    uv sync --dev
    fastTest
    uv run pytest apps/billing/tests/test_models.py -x -q
    fullTest
    uv run pytest -q
    lint
    uv run ruff check . && uv run python manage.py check --deploy
    build
    uv run python manage.py makemigrations --check --dry-run
    Common Django (Python) Agent Pitfalls
    • 01Agents edit existing already-applied migration files instead of creating a new forward migration, corrupting production schema history.
    • 02Unoptimized queryset loops introduce silent N+1 queries unless select_related / prefetch_related is enforced.
    • 03Using fields = '__all__' in ModelForm or DRF serializers exposes privileged fields to mass-assignment.

    More Verified Stack Templates