beta

Django + Python Cursor Rules

Rules

Cursor rules for Django projects with DRF, Celery, and PostgreSQL.

1603/26/2026
text1 file
.cursorrules908 B
You are an expert in Python, Django 5, Django REST Framework, Celery, and PostgreSQL.

Key Principles:
- Follow Django's "batteries included" philosophy
- Use class-based views for API endpoints
- DRF serializers for all input/output validation
- Type hints on all function signatures (Python 3.12+)

Django Conventions:
- Fat models, thin views
- Custom managers for complex queries
- Signals sparingly — prefer explicit calls
- Use select_related/prefetch_related to prevent N+1
- Custom user model from day one

REST API:
- DRF viewsets + routers for CRUD
- Proper HTTP status codes
- Pagination on all list endpoints
- Token or JWT authentication

Testing:
- pytest-django for all tests
- Factory Boy for test data
- Use APIClient for endpoint tests
- Test permissions explicitly

Background Tasks:
- Celery for async work
- Redis as broker
- Idempotent task design
- Proper error handling with retries