A secure and flexible Django REST Framework based API to manage fitness centers like gyms, yoga studios, and more. The API supports full CRUD operations, JWT authentication, and custom filtering options for listing and managing centers.
- ✅ User Registration & JWT Authentication
- ✅ Create, Read, Update, Delete (CRUD) Fitness Centers
- ✅ Role-Based Permissions (Owner, Admin)
- ✅ Filter & Sort Centers by:
- Monthly fee (min/max)
- Facilities (search)
- Verified status
- Category (via URL param)
- Established date and fee (ordering)
- ✅ Owner-only update/delete
- ✅ Test Coverage using
APITestCase
- Backend: Django, Django REST Framework
- Auth: JWT (
djangorestframework-simplejwt) - Database: SQLite (default)
- Testing: Django
APITestCase
fitness_app/ │ ├── models.py # FitnessCenter model ├── views.py # API views with permissions ├── serializers.py # Serializers (not shown here) ├── tests.py # Full test cases using APITestCase fitness/ ├── urls.py # Routes for API endpoints
Uses JWT Authentication for secure login.
- Register:
POST /api/auth/register/ - Login:
POST /api/auth/login/
Returnsaccessandrefreshtokens.
Include Authorization: Bearer <access_token> in headers for protected routes.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register/ |
Register a new user |
POST |
/api/auth/login/ |
Login and get JWT token |
GET |
/api/centers/ |
List all centers (with filters) |
POST |
/api/centers/ |
Create a new center (Authenticated) |
GET |
/api/centers/<pk>/ |
Get details of a center |
PUT/PATCH |
/api/centers/<pk>/ |
Update center (Owner only) |
DELETE |
/api/centers/<pk>/ |
Delete center (Owner only) |
GET |
/api/centers/<category>/ |
Get centers by category (e.g., YOGA) |
- ✅ User registration & JWT login
- ✅ Fetching center list with filters
- ✅ Ordering by monthly fee and established date
- ✅ Owner-based update and delete permission checks
- ✅ Validation:
- Minimum
monthly_fee - Valid
established_date - Unique
name
- Minimum
You can pass query parameters like: /api/centers/?min_fee=1000&max_fee=1500&facilities=Showers&ordering=-established_date
min_fee: Minimum monthly feemax_fee: Maximum monthly feefacilities: Case-insensitive match in facilities textis_verified: Filter by verification statusordering: Fields likemonthly_feeor-established_date
price_per_sessionis calculated as:- price_per_session = monthly_fee / total_sessions
Returned as part of the center's response.
python manage.py testRuns all test cases under fitness_app/tests.py.
git clone https://github.com/yourusername/fitness-api.git
cd fitness-api
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuserpython manage.py runserver- Django >= 4.0
- djangorestframework
- djangorestframework-simplejwt
Md Javed
Django & DRF Developer | Data Scientist
GitHub Profile