beta

Django + Python Rules

Rules

CLAUDE.md for Django projects with Django REST Framework, Celery, and PostgreSQL.

1803/23/2026

Version 1

Published

Initial version

Created 3/23/2026

Initial version — no previous version to compare

CLAUDE.md
# CLAUDE.md — Django

## Commands
- `python manage.py runserver` — dev server
- `python manage.py test` — run tests
- `python manage.py makemigrations` — create migrations
- `python manage.py migrate` — apply migrations
- `python manage.py shell_plus` — enhanced shell

## Code Style
- Follow Django conventions (fat models, thin views)
- Use class-based views for CRUD, function-based for custom logic
- Use Django REST Framework serializers for API validation
- Use select_related/prefetch_related to avoid N+1 queries
- Use Django signals sparingly — prefer explicit calls

## Architecture
- apps/ — Django apps (each is a bounded context)
- core/ — shared utilities, base models, middleware
- api/ — DRF viewsets and serializers
- tasks/ — Celery tasks

## Database
- Always create migrations (never modify the database directly)
- Use Django's ORM — no raw SQL unless performance-critical
- Index foreign keys and frequently filtered fields
- Use transactions for multi-model operations