This is a Django-based Library Management System that allows a librarian to manage books, members, and issued books. It also provides functionalities for members to view their current fines after login .
- Librarian Functions:
- Add, update, delete books
- Issue and return books
- Add, update, delete member
- Member Functions:
- View list of books
- View current fine status
- Python 3.10 or +
- Django 5.0.6
- Django REST Framework
- Django CORS Headers
-
Clone the repository:
git clone https://github.com/Pasindu-Vishmika/lib_backend.git cd lib_backend
-
Install dependencies:
pip install -r requirements.txt
To change the database to MySQL, follow these steps:
-
Install MySQL Client:
pip install mysqlclient
-
Update
DATABASES
insettings.py
:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'your_database_name', 'USER': 'your_database_user', 'PASSWORD': 'your_database_password', 'HOST': 'localhost', # Or the database server IP 'PORT': '3306', # Default MySQL port } }
To change the database to PostgreSQL, follow these steps:
-
Install PostgreSQL Client:
pip install psycopg2-binary
-
Update
DATABASES
insettings.py
:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'your_database_name', 'USER': 'your_database_user', 'PASSWORD': 'your_database_password', 'HOST': 'localhost', # Or the database server IP 'PORT': '5432', # Default PostgreSQL port } }
-
Run migrations:
python manage.py makemigrations python manage.py migrate
-
Create a superuser:
python manage.py createsuperuser
-
Run the development server:
python manage.py runserver
- Login:
POST /api/login/
- Logout:
POST /api/logout/
- Add Book:
POST /api/add-book/
- Get Books:
GET /api/book-list/
- Get Book Details:
GET /api/book/<str:pk>/
- Update Book:
PUT /api/update-book/<str:pk>/
- Delete Book:
DELETE /api/delete-book/<str:pk>/
- Issue Book:
POST /api/issue-book/<str:pk>/
- Return Book:
POST /api/return-book/<str:pk>/
- Add Member:
POST /api/add-member/
- Get Members:
GET /api/member-list/
- Get Member Details:
GET /api/member/<str:pk>/
- Update Member:
PUT /api/update-member/<str:pk>/
- Delete Member:
DELETE /api/delete-member/<str:pk>/
- Get Member Fine:
GET /api/member-fine/
-
Login:
curl -X POST http://127.0.0.1:8000/api/login/ -H "Content-Type: application/json" -d '{"username": "your email", "password": "your password"}'
-
Get Books:
curl -X GET http://127.0.0.1:8000/api/book-list/ -H "Authorization: Token <your-token>"
-
Issue Book:
curl -X POST http://127.0.0.1:8000/api/issue-book/1/ -H "Authorization: Token <your-token>" -H "Content-Type: application/json" -d '{"member_id": 2, "issue_date": "2024-06-01", "due_date": "2024-06-15"}'