A Django-based REST API that simulates a core academic assessment platform.
Built with Django 5+, PostgreSQL, and Django Rest Framework.
- Exam Management: List and retrieve exams with questions (MCQ & Text).
- Secure Submissions: Students can take exams and submit answers.
- Automated Grading:
- Exact Match: Automatically grades MCQs.
- Fuzzy Match: Uses similarity algorithms (Mock AI) to grade text answers.
- Results: Students view their own private submission history.
- Efficiency: Optimized queries using
prefetch_relatedand batch processing to avoid N+1 issues. - Security: JWT Authentication (SimpleJWT) with stateless sessions. User data isolation.
- Database: Normalized PostgreSQL Schema with proper constraints.
- Documentation: Auto-generated Swagger/OpenAPI docs.
- Containerization: Docker support for the database layer.
- Backend: Python 3, Django, Django Rest Framework (DRF)
- Database: PostgreSQL (Dockerized)
- Auth: JWT (djangorestframework-simplejwt)
- Docs: drf-spectacular (OpenAPI 3.0)
- User: Standard Django Auth.
- Exam: Meta-data (title, duration).
- Question: Linked to Exam. Stores
question_type(MCQ/TEXT) andoptions(JSON). - Submission: Links User <-> Exam. Stores final score.
- Answer: Links Submission <-> Question. Stores raw student input and correctness.
Decoupled logic that evaluates a submission.
- MCQ: String comparison (Trimmed/Lowercased).
- Text:
difflib.SequenceMatcherwith >0.8 threshold.
- Python 3.10+
- Docker & Docker Compose (for Postgres)
Create a .env file based on .env.example:
cp .env.example .envConfigure the following variables in .env:
# Django Settings
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# Database Configuration
DB_NAME=assessment_engine_db
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_PORT=5433
# JWT Token Configuration
JWT_ACCESS_TOKEN_LIFETIME_MINUTES=60 # Access token expires in 1 hour
JWT_REFRESH_TOKEN_LIFETIME_DAYS=15 # Refresh token expires in 15 daysInstall dependencies:
pip install -r requirements.txt
# Start Database (Postgres on port 5433)
docker compose up -d# Run Migrations
python3 manage.py migratepython3 manage.py runserverAPI available at http://127.0.0.1:8000/.
Run the rigorous test suite covering Auth, Validation, and Grading limits:
python3 manage.py test coreAccess Swagger UI at:
http://127.0.0.1:8000/api/schema/swagger-ui/
Key Payloads:
- Register:
POST /api/auth/register/{ "username": "...", "password": "..." } - Login:
POST /api/auth/login/-> Get Token -> Authorize - Submit:
POST /api/submit/{ "exam_id": 1, "answers": [{"question_id": 1, "student_answer": "..."}] }
- Exam Listing: Uses
prefetch_related('questions')to fetch all questions for exams in 2 queries instead of N+1. - Submissions: Validates and fetches related Questions in a single batch query (
filter(id__in=...)) during submission processing, reducing database round-trips significantly.