← Tous les modèles

Modèles riches, vues minces, migrations relues, pas de SQL brut sans raison.

Constitution — Django monolith

Version 1.0.0 · Ratified 2026-11-10

These principles hold for every spec, plan and task of the project. A spec may add rules; it never weakens these.

  1. Fat models. Business rules live on models, model methods and custom managers or querysets. A rule that touches one model is a method on that model, not code repeated in views or forms.

  2. Thin views. Views parse the request with a form or serializer, call one model or service method and render the result. A view longer than about 30 lines or with business conditions fails the review.

  3. Migrations reviewed. Every model change ships its generated migration in the same pull request, and makemigrations --check runs in CI. Data migrations use RunPython with a reverse function, and migrations that lock large tables are flagged in the plan.

  4. No raw SQL without a reason. Queries use the ORM. raw(), extra() and cursor.execute need a justification in the plan (a measured query the ORM cannot express) and always pass parameters, never formatted strings.

  5. No N+1 queries. List views use select_related and prefetch_related for the relations they render. Tests assert query counts with assertNumQueries on every list endpoint.

  6. Apps by domain. Each Django app owns one business area with its models, admin, urls and tests. Apps import each other through public functions, not by reaching into another app’s internals.

  7. Settings from the environment. Secrets and per-environment values come from environment variables; DEBUG is off and ALLOWED_HOSTS is explicit outside development. manage.py check --deploy passes before a release.

  8. Tests with the test client. Every view has a test with Django’s test client or pytest-django covering success, permission denied and invalid input. Factories (factory_boy) build data; shared fixtures files are avoided.