Backend Quickstart¶
Quick reference for Django backend development in the DraftForge project.
Prerequisites¶
Just commands automatically activate the virtual environment. No manual activation needed.
Database Operations¶
Migrations¶
Run migrations using just (recommended):
# All environments
just db::migrate::all
# Specific environments
just db::migrate::dev # Development (default)
just db::migrate::test # Test environment
just db::migrate::prod # Production
To create new migrations:
Test Data Population¶
Running the Server¶
Development (Docker)¶
Direct (Local)¶
Note: Use DISABLE_CACHE=true when Redis is unavailable.
Running Tests¶
Backend Tests (Docker - Recommended)¶
# All tests
just test::run 'python manage.py test app.tests -v 2'
# Specific module
just test::run 'python manage.py test app.tests.test_shuffle_draft -v 2'
# Specific test class
just test::run 'python manage.py test app.tests.test_shuffle_draft.GetTeamTotalMmrTest -v 2'
Backend Tests (Local)¶
May hang on cleanup due to Redis/cacheops:
Creating New Endpoints¶
- Add serializer in
backend/app/serializers.py - Add viewset in
backend/app/views.py - Add permissions from
backend/app/permissions.py - Register route in
backend/app/urls.py
Common Commands¶
# Django shell
just py::shell
# Create superuser
just dev::exec backend 'python manage.py createsuperuser'
# Check for issues
just dev::exec backend 'python manage.py check'
Troubleshooting¶
| Issue | Solution |
|---|---|
| Redis connection errors | Use DISABLE_CACHE=true prefix |
| Migrations out of sync | Run just db::migrate::all |
| Module not found | Run ./dev to bootstrap the environment |
| Tests hang on cleanup | Use Docker: just test::run '...' |