This project is an expense sharing application built using Django and Django REST Framework. It allows users to create and manage expenses, split them among different users, and view their balances.
Follow these steps to get the project up and running on your local machine.
- Python 3.8+
- pip (Python package installer)
- virtualenv (optional but recommended)
git clone https://github.com/Indranil0603/Expense-Calculator.git
cd Expense-calculator
virtualenv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
pip install -r requirements.txt
python manage.py migrate
To create a superuser for accessing the Django admin panel, run:
python manage.py createsuperuser
Start the development server with
python manage.py runserver
Visit http://127.0.0.1:8000/
in your web-browser to see the application
Endpoint : POST http://localhost:8000/api/users/
Description: Creates a new user.
example -
curl -X POST http://localhost:8000/api/users/ \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"name": "Example User",
"mobile_number": "1234567890"
}'
Endpoint: GET http://localhost:8000/api/users/<user_id>/
Description: Retrieves details of a specific user by their ID.
example -
curl -X GET http://localhost:8000/api/users/1/
Endpoint: POST http://localhost:8000/api/expenses/
Description: Creates a new expense and splits them according to split method.
-
Equal split
curl -X POST http://localhost:8000/api/expenses/ \ -H "Content-Type: application/json" \ -d '{ "description": "Dinner", "total_amount": 3000, "split_method": "equal", "shares": [ {"user": 1}, {"user": 2}, {"user": 3} ] }'
-
Percentage Split
curl -X POST http://localhost:8000/api/expenses/ \ -H "Content-Type: application/json" \ -d '{ "description": "Party", "total_amount": 4000, "split_method": "percentage", "shares": [ {"user": 1, "percentage": 50}, {"user": 2, "percentage": 25}, {"user": 3, "percentage": 25} ] }'
-
Exact Split
curl -X POST http://localhost:8000/api/expenses/ \ -H "Content-Type: application/json" \ -d '{ "description": "Ride", "total_amount": 2000, "split_method": "exact", "shares": [ {"user": 1, "amount": 1000}, {"user": 2, "amount": 700}, {"user": 3, "amount": 300} ] }'
Endpoint: GET http://localhost:8000/api/expenses/user/<user_id>/
Description: Retrieves all expenses associated with a specific user.
example:
curl -X GET http://localhost:8000/api/expenses/user/1/
Endpoint: GET http://localhost:8000/api/expenses/overall/
Description: Retrieves all expenses in the system.
example:
curl -X GET http://localhost:8000/api/expenses/overall/
Endpoint: GET http://localhost:8000/api/expenses/download-balance-sheet/
Description: Downloads the balance sheet for all users.
example:
curl -X GET http://localhost:8000/api/users/download-balance-sheet/ -O balance_sheet.csv
To run tests run the following command-
python manage.py test expenses_app.tests