Thank you for your interest in contributing to this Django project template! This document provides guidelines to ensure code quality and consistency.
- Test-Driven Development: We aim for 100% test coverage, starting with models and behavior mixins
- Clean Architecture: Keep code modular with clear separation of concerns
- Simplicity Over Complexity: Prefer simple, standard Django patterns over custom frameworks
- Documentation: Document everything, especially behavior mixins and model conventions
-
Clone the repository
git clone https://github.com/yourusername/django-project-template.git cd django-project-template # Add original repository as upstream remote for future improvements git remote add upstream https://github.com/original/django-project-template.git
-
Set up the environment
python -m venv venv source venv/bin/activate pip install uv uv sync --all-extras cp .env.example .env.local # Edit with your private keys
-
Install pre-commit hooks (REQUIRED)
# This ensures code quality for all commits uv run pre-commit install uv run pre-commit install --hook-type pre-push # Verify hooks are working uv run pre-commit run --all-files
-
Run migrations and start the server
python manage.py migrate python manage.py runserver
-
Create a feature branch
git checkout -b feature/descriptive-name
All code quality checks are automatically enforced by pre-commit hooks:
- On every commit: Black, isort, Flake8, Bandit, Django checks
- On push: Critical tests are run
Manual commands (if needed):
# Run all pre-commit checks
uv run pre-commit run --all-files
# Or run individual tools
uv run black .
uv run isort .
uv run flake8 .
uv run mypy .If hooks block your commit, fix the issues and try again. Only bypass with --no-verify in emergencies.
- Use type hints for all function parameters and return values
- Follow the model conventions in MODEL_CONVENTIONS.md
- Group imports: standard library, third-party, Django, local apps
- Write tests before implementing features
- Run tests with coverage reporting:
DJANGO_SETTINGS_MODULE=settings pytest --cov=apps
- Test isolated units with proper mocking
- For behavior mixins, create tests that verify all functionality
python test_behaviors.py
- For model tests, verify field constraints and model methods
- Never use SQLite for tests since the app uses Postgres JSON fields
- Place templates in the root
templates/directory - Place static files in the root
static/directory - Organize apps by domain (common, public, api, etc.)
- Use behavior mixins from
apps.common.behaviors
-
Use Behavior Mixins: Inherit from appropriate mixins in
apps.common.behaviors -
Follow Naming Conventions:
- Boolean fields: start with
is_orhas_ - Datetime fields: end with
_at - Properties: nouns reflecting the value returned
- Methods: verb phrases describing the action
- Boolean fields: start with
-
Document Models:
- Add docstrings explaining model purpose
- List key attributes and properties
- Document special behaviors
- Ensure all tests pass with 100% coverage for your changes
- Update documentation relevant to your changes
- Update the docs/TODO.md to mark completed tasks
- Create a pull request with a clear description of changes
- Address reviewer feedback promptly
- Use the imperative mood ("Add feature" not "Added feature")
- First line: summary (50 chars max)
- Followed by blank line and detailed explanation if needed
- Reference issues: "Fixes #123" or "Relates to #456"
See docs/TODO.md for our current priorities, including:
- Documentation improvements
- Performance optimizations
- Accessibility enhancements
- Admin interface improvements
- API expansion
Thank you for contributing to making this project better!