A simple and robust Inventory Management REST API built using Django Rest Framework.
It supports full CRUD functionality for products with JWT authentication and role-based permissions.
- โ CRUD operations with proper status codes
- ๐ JWT-based authentication (Register/Login)
- ๐ฅ Role-based access:
- Unauthenticated users can view products
- Only admin/staff can create, update, or delete products
- ๐งพ Unique barcode constraint with custom error messages
- ๐ Filtering by price range
- ๐ Ordering by
unit_priceortotal_price - ๐ก
total_price = unit_price ร quantityauto-calculated in:- List view
- Create response
- Update response
- โ Error handling for duplicate barcode entries
- Backend: Django, Django REST Framework
- Auth: JWT (
djangorestframework-simplejwt) - Database: SQLite (default)
- Testing: Django
APITestCase
inventory_app/ โ โโโ models.py # Product model โโโ views.py # API views with permissions and validations โโโ serializers.py # Custom serializer with total_price logic โโโ tests.py # Comprehensive test cases using APITestCaseinventory/ โโโ urls.py # Routes for API endpoints
python manage.py testRuns all test cases under inventory_app/tests.py. Covers authentication, CRUD, permissions, filters, ordering, and validations.
git clone https://github.com/mdjaved24/inventory-api.git
cd inventory-api
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuserpython manage.py runserver- Register:
/register/ - Login:
/login/
Returns access and refresh tokens using JWT.
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /register/ | Public | Register a new user |
| POST | /login/ | Public | Login and receive JWT token |
| GET | /products/ | Public | List all products |
| POST | /products/ | Admin Only | Create a new product |
| GET | /products/<id>/ | Public | Get product details |
| PUT | /products/<id>/ | Admin Only | Fully update product |
| PATCH | /products/<id>/ | Admin Only | Partially update product |
| DELETE | /products/<id>/ | Admin Only | Delete a product |
- Django >= 4.0
- djangorestframework
- djangorestframework-simplejwt
Md Javed
Django & DRF Developer | Data Scientist
GitHub Profile