This project demonstrates a robust implementation of Django and Python development with a focus on APIs, custom authentication, and task scheduling. It integrates Microsoft SQL Server (Local) as the database backend and utilizes Celery for asynchronous and scheduled tasks. The project is containerized using Docker for seamless deployment, except for the SQL Server, which needs to be set up locally.
- Developed using Django with Python 3.9.
- Uses Microsoft SQL Server (Local) as the database backend.
- Implements JWT (JSON Web Tokens) for secure user authentication.
- Tokens are set to expire after 5 minutes for enhanced security.
- Protects all endpoints to ensure only authenticated users can access them.
- Allows authenticated users to create tasks by providing a
title
andduration
. - Automatically stores timestamps and associates tasks with the logged-in user.
- Retrieves the last 4 tasks created by the logged-in user using Django's filtering capabilities.
- Fetches a specific task created by the logged-in user.
- Uses a raw SQL query for implementation.
- Allows updating only the
title
of a task. - Prevents updates to the
duration
field. - Implemented using a raw SQL query.
- Enables users to delete tasks they created.
- Prevents deletion of tasks created by other users.
- Includes comprehensive test cases to validate all API endpoints and custom functionalities.
- Implements a Django management command to:
- Iterate through all tasks in the database.
- Display each task at intervals of 10 seconds (using custom output instead of
print()
).
- Integrated Celery with Redis to manage asynchronous task execution.
- Handles background task processing efficiently.
- Configured Celery Beat to run scheduled tasks:
- A scheduled task runs every 1 minute, printing the
title
,duration
, and timestamps of tasks created by the user withid=1
.
- A scheduled task runs every 1 minute, printing the
- Fully containerized project with Docker for deploying the Django application and Celery services.
- The Dockerfile and docker-compose.yaml configure the following services:
- Django App: The main web application.
- Redis: A message broker for Celery.
- Celery Worker: Executes background tasks.
- Celery Beat: Manages task scheduling.
Note: The SQL Server is not included in the Docker setup and must be installed and configured locally.
- Docker and Docker Compose.
- Microsoft SQL Server installed locally.
- Django configured to connect to the local SQL Server.
git clone <repo_url>
cd <repo_directory>
- Install Microsoft SQL Server locally.
- Update the
DATABASES
setting insettings.py
to match your local SQL Server configuration.
Example:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sql_server',
'NAME': '<database_name>',
'USER': '<username>',
'PASSWORD': '<password>',
'HOST': 'localhost',
'PORT': '1433',
}
}
- Start the Django app, Redis, and Celery services using Docker:
docker-compose up --build
- Apply migrations to the SQL Server:
docker exec -it <container_name> python manage.py migrate
- The Django app will be available at
http://localhost:8000
.
- Django: Web application framework.
- Python 3.9: Programming language.
- Microsoft SQL Server: Local database backend.
- JWT: Authentication and authorization.
- Celery: Asynchronous task processing.
- Redis: Message broker for Celery.
- Celery Beat: Scheduled task management.
- Docker: Application containerization.
- SQL Server is configured locally and is not included as part of the Docker containers.
- Celery and Celery Beat are automatically started within the Docker containers.
- Scheduled tasks run periodically without any additional manual configuration.
- Test the APIs using tools like Postman for validation.