Django Patterns
Patterns and conventions for building Django applications. Follow the philosophy of fat
models and thin views, prefer explicit over implicit, and adhere to Django conventions
for project structure and naming.
Core Principles
- Fat models, thin views -- Place business logic in model methods and managers, keep
views focused on request handling and response rendering
- Explicit over implicit -- Prefer named URL patterns, explicit field definitions,
and clear import paths over magic or convention-only behavior
- Django conventions -- Follow the framework's naming conventions for apps, models,
URLs, and templates to maximize compatibility with third-party packages
- DRY with discipline -- Use abstract models, mixins, and shared utilities to avoid
repetition, but keep indirection minimal and traceable
When to Use
Apply these patterns when working on any project that lists django in its dependencies.
Detect this by checking pyproject.toml, requirements.txt, or Pipfile for Django.
Running Locally
Always run Django apps locally without Docker:
ENVIRONMENT=local poetry run python src/manage.py runserver 0.0.0.0:8000
Type Hints
Use | None instead of Optional for all type annotations:
def get_user(user_id: int) -> User | None:
...
Logging
Use emojis as prefixes in log messages:
logger.info("✅ Order %s created successfully", order.id)
logger.warning("⚠️ Payment retry #%d for order %s", attempt, order.id)
logger.error("❌ Failed to process webhook: %s", exc)
Reference Documents
- models.md -- Django ORM patterns: fields, querysets,
managers, migrations, abstract models, constraints
- views.md -- Views, URL routing, forms, templates, middleware,
settings organization
- admin-signals-middleware.md -- Admin
customization, signals, middleware, management commands
- ninja.md -- Django Ninja integration: routers, schemas,
authentication, error handling, testing
Source: weorbitant/compound-engineering-feat-python-plugin — distributed by TomeVault.
1---2name: django-patterns-293description: Django core patterns for models, views, admin, signals, middleware, and Django Ninja APIs. Use when working on projects with django in their dependencies. Use when this capability is needed.4---56# Django Patterns78Patterns and conventions for building Django applications. Follow the philosophy of fat9models and thin views, prefer explicit over implicit, and adhere to Django conventions10for project structure and naming.1112## Core Principles1314- **Fat models, thin views** -- Place business logic in model methods and managers, keep15 views focused on request handling and response rendering16- **Explicit over implicit** -- Prefer named URL patterns, explicit field definitions,17 and clear import paths over magic or convention-only behavior18- **Django conventions** -- Follow the framework's naming conventions for apps, models,19 URLs, and templates to maximize compatibility with third-party packages20- **DRY with discipline** -- Use abstract models, mixins, and shared utilities to avoid21 repetition, but keep indirection minimal and traceable2223## When to Use2425Apply these patterns when working on any project that lists `django` in its dependencies.26Detect this by checking `pyproject.toml`, `requirements.txt`, or `Pipfile` for Django.2728## Running Locally2930Always run Django apps locally without Docker:3132```bash33ENVIRONMENT=local poetry run python src/manage.py runserver 0.0.0.0:800034```3536## Type Hints3738Use `| None` instead of `Optional` for all type annotations:3940```python41def get_user(user_id: int) -> User | None:42 ...43```4445## Logging4647Use emojis as prefixes in log messages:4849```python50logger.info("✅ Order %s created successfully", order.id)51logger.warning("⚠️ Payment retry #%d for order %s", attempt, order.id)52logger.error("❌ Failed to process webhook: %s", exc)53```5455## Reference Documents5657- [models.md](./references/models.md) -- Django ORM patterns: fields, querysets,58 managers, migrations, abstract models, constraints59- [views.md](./references/views.md) -- Views, URL routing, forms, templates, middleware,60 settings organization61- [admin-signals-middleware.md](./references/admin-signals-middleware.md) -- Admin62 customization, signals, middleware, management commands63- [ninja.md](./references/ninja.md) -- Django Ninja integration: routers, schemas,64 authentication, error handling, testing6566---67> Source: [weorbitant/compound-engineering-feat-python-plugin](https://github.com/weorbitant/compound-engineering-feat-python-plugin) — distributed by [TomeVault](https://tomevault.io).68<!-- tomevault:4.0:skill_md:2026-05-22 -->