Language / ΠΠΎΠ²Π°: English | Π£ΠΊΡΠ°ΡΠ½ΡΡΠΊΠ°
A full-stack e-commerce shop for home-brewing ingredients β Django web UI + DRF REST API, on PostgreSQL & Docker.
π Live Demo
Free hosting β first load may take ~40s to wake. Demo login: admin / check Render dashboard for password.
- Features
- Tech Stack
- Project Structure
- Quick Start β Docker
- Local Development
- REST API & JWT
- Admin Panel
- Tests & Linters
- Deployment on Render
- Checklist
| Area | What's included |
|---|---|
| Catalog | Product listing with pagination, search, category & price filters, sorting by price / newest / popularity |
| Product page | Full details, average star rating, review section β reviewable only after "delivered" status |
| Cart | Session-based cart: add, remove, update quantity, stock validation, live total |
| Checkout | Shipping form, order creation, email notification to user & admin |
| Account | Registration, login/logout (session auth), order history with status filter, profile & password edit |
| Admin | Custom analytics dashboard, role-based permissions (superuser / Manager), search, filters, bulk actions |
| REST API | JWT-protected endpoints for products, orders, cart, reviews, users; Swagger/OpenAPI docs |
| Deployment | Docker + docker-compose, Render Blueprint (render.yaml), WhiteNoise for static files |
| Layer | Technology |
|---|---|
| Backend | Django 4.2, Python 3.11 |
| REST API | Django REST Framework 3.17, SimpleJWT |
| API Docs | drf-spectacular (Swagger/OpenAPI) |
| Database | PostgreSQL 15 |
| Auth | Session (web UI) + JWT (API) |
| Static files | WhiteNoise |
| Containerisation | Docker, docker-compose |
| Deployment | Render (free tier, Docker runtime) |
| Testing | pytest-django, pytest-cov |
| Linting | flake8, mypy |
hop-and-barley/
βββ api/ # DRF ViewSets, serializers, JWT endpoints
βββ config/ # Django settings, URLs, WSGI
βββ docker/ # entrypoint.sh (migrate β seed β start)
βββ orders/ # Order & cart logic, analytics view, admin
βββ pages/ # Static content pages (Guides, Community)
βββ payments/ # Payment model (mock)
βββ products/ # Product & category models, catalog views
βββ reviews/ # Review model & submission view
βββ static/ # CSS, JS, product images
βββ templates/ # Django HTML templates
βββ tests/ # API & integration tests
βββ users/ # Registration, profile, password change
βββ .github/workflows/ # GitHub Actions CI
βββ docker-compose.yml
βββ Dockerfile
βββ render.yaml # Render deployment blueprint
βββ requirements.txt
βββ manage.py
The fastest way to get a running instance with demo data:
git clone https://github.com/marko-onechance/django_brew_shop.git
cd django_brew_shop
docker-compose up --buildOn first start the entrypoint automatically:
- Runs all database migrations
- Seeds the demo product catalog with images
- Creates a
Managerpermission group - Creates a demo superuser (
admin/admin1234)
Open http://localhost:8000 β the shop is ready.
- Python 3.11+
- PostgreSQL 15 running locally (or use Docker just for DB)
- pip
# 1. Clone & create virtual environment
git clone https://github.com/marko-onechance/django_brew_shop.git
cd django_brew_shop
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# 2. Install dependencies
pip install -r requirements.txt
# 3. Configure environment
cp .env.example .env
# Edit .env β set DATABASE_NAME / USER / PASSWORD / HOST to match your local PG
# 4. Apply migrations and seed demo data
python manage.py migrate
python manage.py seed_catalog
python manage.py create_roles
python manage.py create_demo_admin # creates admin / admin1234
# 5. Start the dev server
python manage.py runserverBase URL: /api/
Interactive docs: http://localhost:8000/api/docs/
# 1. Obtain tokens
curl -X POST http://localhost:8000/api/users/login/ \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "admin1234"}'
# Response:
# { "access": "eyJ...", "refresh": "eyJ..." }
# 2. Use access token in subsequent requests
curl http://localhost:8000/api/orders/ \
-H "Authorization: Bearer eyJ..."
# 3. Refresh an expired access token
curl -X POST http://localhost:8000/api/users/token/refresh/ \
-H "Content-Type: application/json" \
-d '{"refresh": "eyJ..."}'| Method | URL | Auth | Description |
|---|---|---|---|
| GET | /api/products/ |
β | Product list (search, filter, paginate) |
| GET | /api/products/{id}/ |
β | Product detail |
| GET/POST | /api/products/{id}/reviews/ |
POST: JWT | List or submit a review |
| GET/POST | /api/orders/ |
JWT | User's orders |
| GET/PATCH/DELETE | /api/orders/{id}/ |
JWT | Single order |
| GET/POST/PATCH/DELETE | /api/cart/ |
β | Cart management |
| POST | /api/users/register/ |
β | Create account |
| POST | /api/users/login/ |
β | Obtain JWT tokens |
| POST | /api/users/token/refresh/ |
β | Refresh access token |
| GET | /api/docs/ |
β | Swagger UI |
| GET | /api/schema/ |
β | OpenAPI schema (JSON) |
Access at http://localhost:8000/admin/
- Products & Categories β full CRUD with image upload, slug auto-fill, stock tracking
- Orders β inline order items, bulk status actions (Mark as Shipped / Delivered), revenue action
- Reviews β moderation, filter by rating and product
- Users β manage accounts and group memberships
- Analytics β custom dashboard at
/admin/orders/order/analytics/with:- Total revenue, total orders, revenue last 30 days, total users
- Orders breakdown by status with per-status revenue
- Top 10 products by units sold and revenue
- Revenue by category
- Daily orders chart (last 30 days)
Role-based permissions:
| Role | Can view | Can change | Can add | Can delete |
|---|---|---|---|---|
| Superuser | β all | β all | β all | β all |
| Manager | β orders, products | β orders, products | β | β |
| Regular user | β | β | β | β |
# Run all tests
python -m pytest
# Run with coverage report
python -m pytest --cov=. --cov-report=term-missing
# Lint
flake8 .
# Type checking
mypy . --ignore-missing-importsCurrent test suite: 36 tests, all passing.
Coverage areas:
- Product API (list, detail, 404)
- Order API (auth-guard, user isolation)
- User registration & JWT auth
- Swagger / schema endpoints
- Product & Category models
- Product catalog views
- User registration, login, logout, account page
- Review model (creation, uniqueness constraint, average rating)
The repo includes a render.yaml Blueprint that provisions a free PostgreSQL database and a web service automatically.
Steps:
- Push the repository to GitHub
- Go to render.com β New β Blueprint
- Connect your GitHub repository
- Render detects
render.yamland creates both the database and the web service - Click Apply β first deploy takes ~3 minutes
On every deploy, the Docker entrypoint runs migrations and re-seeds demo data, so the demo catalog is always populated even after ephemeral storage resets.
Environment variables set automatically by Render:
| Variable | Source |
|---|---|
SECRET_KEY |
Auto-generated by Render |
DATABASE_URL |
Linked PostgreSQL service |
DEBUG |
False |
ALLOWED_HOSTS |
.onrender.com |
SESSION_COOKIE_SECURE |
True |
CSRF_COOKIE_SECURE |
True |
- Project starts with
docker-compose up - PostgreSQL database
- Product catalog: filters, search, pagination
- Product detail page: info, reviews, add-to-cart
- Cart: manage items, calculate total, stock validation
- Checkout: order creation, email notification, form validation
- Account: registration, login, order history, profile editing
- REST API: JWT auth, Swagger docs, permission scoping
- Admin panel: analytics, filters, custom actions, role-based access
- Swagger/OpenAPI docs accessible and functional
- Type annotations and docstrings throughout
- Linters (flake8/mypy) pass without critical errors
- 36 tests β all passing
- README is complete and clear
- Deployment configured for Render