- Description
- Technologies Used
- Features
- Getting Started
- Accessing the Application
- Project Structure
- Additional Resources
Welcome to the Library Tracking System! This project is a comprehensive application built with Python, Django, Django REST Framework (DRF), and Celery. It manages authors, books, members, and loans within a library context. The application is fully containerized using Docker, allowing for easy setup and deployment. Whether you're a developer looking to explore the project or setting it up for development purposes, this README will guide you through the necessary steps.
- Python 3.9
- Django 4.2
- Django REST Framework
- Celery 5.3
- Redis 6
- PostgreSQL 13
- Docker & Docker Compose
- Author Management: Create, read, update, and delete authors.
- Book Management: Manage books with genres, ISBNs, and availability status.
- Member Management: Handle library members linked to Django user accounts.
- Loan Management: Track book loans and returns.
- API Endpoints: CRUD operations for all models using Django REST Framework.
- Asynchronous Tasks: Celery tasks for sending loan notifications and overdue reminders.
- Admin Interface: Django admin panel for data management.
- Docker-Ready: Easy setup and deployment using Docker and Docker Compose.
Ensure you have the following installed on your machine:
-
Clone the Repository
git clone https://gitlab.com/search-atlas-interviews/django-library-tracking-system cd django-library-tracking-system # If you dont have a prefered version control, we recommend https://github.com/new (free) git remote rename origin upstream git remote add origin [URL of your newly created repo: https://github.com/...] git push -u origin main
-
Create a
.env
FileIn the root directory, create a
.env
file to store environment variables.touch .env
Content of
.env
:# .env DEBUG=1 DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] DATABASE_URL=postgres://library_user:library_password@db:5432/library_db CELERY_BROKER_URL=redis://redis:6379/0 CELERY_RESULT_BACKEND=redis://redis:6379/0 SECRET_KEY=your-secret-key DEFAULT_FROM_EMAIL=[email protected]
Note: Replace
your-secret-key
with a secure key. Ensure that.env
is included in.gitignore
to prevent committing sensitive information. -
Build and Run Docker Containers
docker-compose build docker-compose up
This command will:
- Start PostgreSQL (
db
) and Redis (redis
) services. - Build and run the Django application (
web
). - Run the Celery worker (
celery
).
- Start PostgreSQL (
-
Initialize the Django Project
In a separate terminal, apply migrations and create a superuser.
docker-compose run web python manage.py makemigrations docker-compose run web python manage.py migrate docker-compose run web python manage.py createsuperuser
Follow the prompts to create a superuser account.
Start all services with Docker Compose:
docker-compose up
Stopping the Services:
To stop the running containers, press CTRL+C
in the terminal where docker-compose up
is running, then execute:
docker-compose down
- URL: http://localhost:8000/admin/
- Login: Use the superuser credentials you created during setup.
- Functionality: Manage authors, books, members, and loans through the admin panel.
- Base URL: http://localhost:8000/api/
- Endpoints:
/api/authors/
: CRUD operations for authors./api/books/
: CRUD operations for books./api/members/
: CRUD operations for members./api/loans/
: CRUD operations for loans.
- Access: Use tools like Postman, cURL, or the DRF browsable API to interact with the endpoints.
After following all the setup steps, your project directory (library-tracking-system/
) should look like this:
library-tracking-system/
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── .env
├── .gitignore
├── manage.py
├── library_system/
│ ├── __init__.py
│ ├── asgi.py
│ ├── celery.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── library/
├── __init__.py
├── admin.py
├── apps.py
├── models.py
├── serializers.py
├── tasks.py
├── tests.py
└── views.py
- Django Documentation: https://docs.djangoproject.com/en/4.2/
- Django REST Framework Documentation: https://www.django-rest-framework.org/
- Celery Documentation: https://docs.celeryproject.org/en/stable/
- Docker Documentation: https://docs.docker.com/
- PostgreSQL Documentation: https://www.postgresql.org/docs/
-
Docker Issues:
- Ensure Docker and Docker Compose are installed correctly.
- Check if ports
8000
,5432
, and6379
are free or adjust them indocker-compose.yml
.
-
Environment Variables:
- Double-check the
.env
file for correct configurations. - Ensure sensitive information like
SECRET_KEY
is set properly.
- Double-check the
-
Migrations:
- If you encounter migration issues, try resetting the database volumes:
docker-compose down -v docker-compose up --build
- If you encounter migration issues, try resetting the database volumes:
-
Celery Worker Not Running:
- Ensure the Celery service is defined correctly in
docker-compose.yml
. - Check logs for any errors related to Celery.
- Ensure the Celery service is defined correctly in
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
Thank you for setting up the Library Tracking System! If you have any questions or need further assistance, please reach out to the project maintainer.