Courses APP - manishgupta248/Project_Mishika_1 GitHub Wiki
Project_Mishika_3 - Courses App
The courses app is a Django-based module designed to manage academic courses and syllabi within a university system. Integrated with a Next.js frontend, it provides a robust API for CRUD operations, supports soft deletion, and includes admin functionalities with import/export capabilities. Built with scalability and maintainability in mind, it leverages modern Django packages and best practices.
Features
Core Functionality
- Course Management:
-
Create, read, update, and soft-delete courses with unique `course_code` identifiers.
-
Fields include `course_name`, `course_category` (Compulsory/Elective), `type` (Theory, Practical, etc.), `cbcs_category` (Core, DSE, etc.), `maximum_credit`, and `discipline` (linked to Department).
-
Audit fields (`created_by`, `created_at`, `updated_by`, `updated_at`) auto-populated using `django-currentuser`.
-
- Syllabus Management:
-
Manage syllabus versions for each course with fields like `syllabus_file` (PDF uploads), `version` (e.g., 1.0), `description`, and `course_name` (auto-populated).
-
Includes `uploaded_by` and `uploaded_at` for tracking uploads, with soft deletion support.
-
- Soft Deletion:
-
Records are marked as `is_deleted=True` instead of being permanently removed, ensuring data retention and auditability.
-
API (Django REST Framework)
- Endpoints:
/courses/
- List/create courses./courses/{course_code}/
- Retrieve/update/soft-delete a course./syllabi/
- List/create syllabi./syllabi/{id}/
- Retrieve/update/soft-delete a syllabus./choices/course-categories/
- List course category options./choices/course-types/
- List course type options./choices/cbcs-categories/
- List CBCS category options.
- Filtering & Search:
-
Filter courses by `discipline`, `course_category`, `type`, `cbcs_category`, `is_deleted`.
-
Search courses by `course_code` and `course_name`.
-
Filter syllabi by `course`, `version`, `is_deleted`.
-
Search syllabi by `course__course_code`, `course_name`, `version`.
-
- Pagination:
-
Customizable page sizes (10 for courses, 5 for syllabi) with `limit` query param.
-
- Permissions:
-
Public read access (list, retrieve); authenticated write access (create, update); admin-only soft deletion.
-
- OpenAPI Documentation:
-
Integrated with `drf-spectacular` for interactive Swagger UI and Redoc documentation at `/api/schema/swagger-ui/` and `/api/schema/redoc/`.
-
Admin Interface
- Course Admin:
-
List view with filters (`course_category`, `type`, `cbcs_category`, `is_deleted`, `created_at`) and search (`course_code`, `course_name`).
-
Import/export via Excel using `django-import-export` with validation for `course_code`, enums, and `maximum_credit`.
-
- Syllabus Admin:
-
List view with filters (`course`, `is_deleted`, `uploaded_at`) and search (`course__course_code`, `course_name`, `version`).
-
Import/export support with validation for `version` and course existence.
-
- Audit Logging:
-
Tracks import actions in Django’s `LogEntry` table.
-
Validation
- Model-Level:
course_code
must be alphanumeric.version
must follow X.Y format (e.g., 1.0).
- File Uploads:
syllabus_file
restricted to PDFs under 5MB viavalidate_pdf
invalidators.py
.
Integrations
- Django-CurrentUser: Auto-populates
created_by
,updated_by
, anduploaded_by
based on the authenticated user. - Django-Import-Export: Enables bulk import/export of courses and syllabi in Excel format.
- Openpyxl: Supports Excel file handling for import/export.
- DRF-Spectacular: Generates OpenAPI 3.0 schema for API documentation.
- Django-Filter: Enables easy filtering of API endpoints.
Setup Instructions
Prerequisites
- Python 3.13
- Node.js (for Next.js frontend)
- PostgreSQL (or your preferred database)
Installation
-
Clone the Repository:
git clone <repository-url> cd Project_Mishika_3/backend
-
Set Up Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
Ensure
requirements.txt
includes:django djangorestframework django-currentuser django-import-export openpyxl drf-spectacular django-filter
-
Configure Settings:
Update
settings.py
:INSTALLED_APPS = [ ... 'django_currentuser', 'rest_framework', 'drf_spectacular', 'django_filters', 'import_export', 'academics', 'courses', ] MIDDLEWARE = [ ... 'django_currentuser.middleware.ThreadLocalUserMiddleware', ] REST_FRAMEWORK = { 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], } SPECTACULAR_SETTINGS = { 'TITLE': 'University API', 'DESCRIPTION': 'API for managing courses and syllabi', 'VERSION': '1.0.0', }
-
Apply Migrations:
python manage.py makemigrations python manage.py migrate
-
Create Superuser:
python manage.py createsuperuser
-
Run the Server:
python manage.py runserver
- API:
http://localhost:8000/courses/
- Admin:
http://localhost:8000/admin/
- Schema:
http://localhost:8000/api/schema/swagger-ui/
- API:
Future Scope for Improvements
- Enhanced Validation:
-
Add more robust checks (e.g., duplicate syllabus versions per course, file content validation for PDFs).
- Implement custom validation for
maximum_credit
based oncbcs_category
.
-
- API Enhancements:
- Versioning: Introduce API versioning (e.g.,
/v1/courses/
) using DRF’s versioning tools. - Rate Limiting: Add throttling for public endpoints to prevent abuse.
- Custom Responses: Standardize API responses with a custom renderer (e.g.,
{"status": "success", "data": ...}
).
- Versioning: Introduce API versioning (e.g.,
- File Storage:
- Integrate cloud storage (e.g., AWS S3) for
syllabus_file
usingdjango-storages
for scalability. - Add file versioning or archival for replaced syllabus files.
- Integrate cloud storage (e.g., AWS S3) for
- Admin Improvements:
- Add inline editing for syllabi within the
CourseAdmin
interface. - Implement custom actions (e.g., bulk soft-delete, export filtered results).
- Add inline editing for syllabi within the
- Audit & History:
- Integrate
django-simple-history
to track all changes toCourse
andSyllabus
records. - Enhance
LogEntry
logging with more detailed change messages.
- Integrate
- Frontend Integration:
- Develop Next.js components for real-time course/syllabus management (e.g., drag-and-drop file uploads).
- Add client-side validation mirroring server-side rules.
- Performance:
- Add caching (e.g., Redis) for frequently accessed endpoints like
/choices/*
. - Optimize querysets with
prefetch_related
for related models (e.g., `
- Add caching (e.g., Redis) for frequently accessed endpoints like