This project is an e-commerce platform built with Django. It includes product management, user authentication, and shopping cart functionality.
- User registration and authentication
- Product and category management
- Shopping cart system
- API support with Django REST Framework
- Extensive test coverage with pytest
- Advanced filtering options for product search
- Scalability β The project is built with Django, making it easy to scale as needed.
- Modular Structure β The application follows Djangoβs best practices, making it easy to extend and maintain.
- API Ready β Fully integrated with Django REST Framework, allowing easy API expansion.
- Secure Authentication β Implements Djangoβs built-in authentication system for secure user management.
- Customizable β Can be modified to fit specific business needs.
- Well-Tested β Includes numerous automated tests using pytest to ensure reliability and stability.
- Advanced Filtering β Products can be filtered based on multiple parameters, improving the user experience.
The project is divided into three main Django applications:
- Users App β Handles user authentication, registration, and profile management.
- Products App β Manages product listings and categories.
- Cart App β Manages the shopping cart functionality.
- Endpoint:
POST /api/auth/register/
- Description: Registers a new user.
- Request Body:
{ "username": "testuser", "email": "test@example.com", "password": "securepassword" }
- Response:
{ "id": 1, "username": "testuser", "email": "test@example.com" }
- Endpoint:
POST /api/auth/login/
- Description: Authenticates a user and returns a token.
- Request Body:
{ "username": "testuser", "password": "securepassword" }
- Response:
{ "token": "abcdef123456" }
- Endpoint:
GET /api/auth/profile/
- Description: Retrieves or updates the user profile.
- Response:
{ "id": 1, "username": "testuser", "email": "test@example.com" }
- Endpoint:
GET /api/products/
- Description: Retrieves a paginated list of all products.
- Response:
[ { "id": 1, "name": "Laptop", "brand": "Asus", "description": "A high-performance laptop", "price": 1200.99, "category": 1 } ]
- Endpoint:
POST /api/products/
- Description: Creates a new product.
- Request Body:
{ "name": "Smartphone", "brand": "Apple", "description": "Latest model with great features", "price": 899.99, "category": "Electronics" }
- Response:
{ "id": 2, "name": "Smartphone", "brand": "Apple", "description": "Latest model with great features", "price": 899.99, "category": "Electronics" }
- Endpoint:
GET /api/products/?category=<category_name>&price_min=<min>&price_max=<max>
- Description: Filters products by category, price range, and other attributes.
- Endpoint:
POST /api/cart/add/
- Description: Adds a product to the userβs cart.
- Request Body:
{ "product_id": 1, "quantity": 2 }
- Response:
{ "message": "Product added to cart" }
- Endpoint:
GET /api/cart/
- Description: Retrieves the current contents of the user's cart.
- Endpoint:
DELETE /api/cart/remove/<id>/
- Description: Removes a product from the cart.
This project is thoroughly tested using pytest to ensure high reliability and prevent regressions. The test suite includes:
- Unit tests for models, views, and serializers
- Integration tests for API endpoints
- Functional tests for core user interactions
- Performance testing to optimize response times
Run the test suite with:
pytest
- Clone the repository
git clone https://github.com/sonwayr/e_shop.git cd shop_pr
- Create a virtual environment and install dependencies
python -m venv venv source venv/bin/activate # For Linux/Mac venv\Scripts\activate # For Windows pip install -r requirements.txt
- Apply migrations and create a superuser
python manage.py migrate python manage.py createsuperuser
- Run the server
python manage.py runserver
- Python, Django, Django REST Framework
- PyJWT for authentication
- Django extensions
- Django Filters for advanced product filtering
- HTML, CSS, JavaScript, Bootstrap
- Pytest for automated testing
- SQLite (can be replaced with PostgreSQL)
This project is licensed under the MIT License.