Skip to content

MayurUghade03/django-intern-assignment

Repository files navigation

Django Intern Assignment - Modular Entity and Mapping System

Production-ready Django REST Framework backend built using strict APIView architecture for managing:

  • Vendors
  • Products
  • Courses
  • Certifications
  • Hierarchical mappings:
    • Vendor -> Product
    • Product -> Course
    • Course -> Certification

Technology Stack

  • Django 5.1.6
  • Django REST Framework 3.15.2
  • drf-yasg 1.21.8 (Swagger + ReDoc)
  • SQLite (default, can be swapped for PostgreSQL in production)

Key Constraints Satisfied

  • Separate app per master entity:
    • vendor
    • product
    • course
    • certification
  • Separate app per mapping:
    • vendor_product_mapping
    • product_course_mapping
    • course_certification_mapping
  • APIs implemented using APIView only
  • No ViewSet, ModelViewSet, GenericAPIView, mixins, or routers
  • Manual queryset filtering by query params
  • Validation for duplicate mappings and single-primary-per-parent rule
  • drf-yasg integrated with /swagger/ and /redoc/

Project Structure

project/
├── certification/
├── common/
├── course/
├── course_certification_mapping/
├── product/
├── product_course_mapping/
├── project/
├── vendor/
├── vendor_product_mapping/
├── manage.py
├── requirements.txt
└── README.md

Setup Instructions

1. Create and activate virtual environment

Windows PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

2. Install dependencies

pip install -r requirements.txt

3. Run migrations

python manage.py makemigrations
python manage.py migrate

4. (Optional) Seed initial data

python manage.py seed_data

5. Run server

python manage.py runserver

API Documentation

  • Swagger UI: http://127.0.0.1:8000/swagger/
  • ReDoc: http://127.0.0.1:8000/redoc/

API Endpoints

Master APIs

  • GET /api/vendors/

  • POST /api/vendors/

  • GET /api/vendors/{id}/

  • PUT /api/vendors/{id}/

  • PATCH /api/vendors/{id}/

  • DELETE /api/vendors/{id}/

  • GET /api/products/

  • POST /api/products/

  • GET /api/products/{id}/

  • PUT /api/products/{id}/

  • PATCH /api/products/{id}/

  • DELETE /api/products/{id}/

  • GET /api/courses/

  • POST /api/courses/

  • GET /api/courses/{id}/

  • PUT /api/courses/{id}/

  • PATCH /api/courses/{id}/

  • DELETE /api/courses/{id}/

  • GET /api/certifications/

  • POST /api/certifications/

  • GET /api/certifications/{id}/

  • PUT /api/certifications/{id}/

  • PATCH /api/certifications/{id}/

  • DELETE /api/certifications/{id}/

Mapping APIs

  • GET /api/vendor-product-mappings/

  • POST /api/vendor-product-mappings/

  • GET /api/vendor-product-mappings/{id}/

  • PUT /api/vendor-product-mappings/{id}/

  • PATCH /api/vendor-product-mappings/{id}/

  • DELETE /api/vendor-product-mappings/{id}/

  • GET /api/product-course-mappings/

  • POST /api/product-course-mappings/

  • GET /api/product-course-mappings/{id}/

  • PUT /api/product-course-mappings/{id}/

  • PATCH /api/product-course-mappings/{id}/

  • DELETE /api/product-course-mappings/{id}/

  • GET /api/course-certification-mappings/

  • POST /api/course-certification-mappings/

  • GET /api/course-certification-mappings/{id}/

  • PUT /api/course-certification-mappings/{id}/

  • PATCH /api/course-certification-mappings/{id}/

  • DELETE /api/course-certification-mappings/{id}/

Filtering Examples

  • GET /api/products/?vendor_id=1
  • GET /api/courses/?product_id=2
  • GET /api/certifications/?course_id=3
  • GET /api/vendor-product-mappings/?vendor_id=1&primary_mapping=true

Validation Rules Implemented

  • Required field checks through serializers
  • Unique code validation for all master entities
  • Duplicate mapping prevention at serializer + DB constraint levels
  • FK validation via PrimaryKeyRelatedField
  • Only one active primary_mapping=True per parent in each mapping layer

Error Handling

  • 200 OK, 201 Created, 400 Bad Request, 404 Not Found
  • Global DRF custom exception handler returns JSON 500 Internal Server Error payload

Bonus Features Included

  • Abstract base model (TimeStampedActiveModel) for shared fields
  • Soft delete (is_active=False) on DELETE endpoints
  • Reusable object retrieval utility (get_object_or_404_message)
  • Nested mapping API responses (parent/child details included)
  • Seed data management command (seed_data)
  • Unit tests for API and mapping validations

Sample Request Bodies

Create Vendor

{
  "name": "Acme Vendor",
  "code": "VENDOR-100",
  "description": "Global training vendor",
  "is_active": true
}

Create Vendor-Product Mapping

{
  "vendor_id": 1,
  "product_id": 1,
  "primary_mapping": true,
  "is_active": true
}

Running Tests

python manage.py test

Submission Checklist

  • Modular app structure
  • APIView-only CRUD APIs
  • Validation rules
  • Swagger + ReDoc
  • Admin registrations
  • Seed command
  • Unit tests

About

Modular Django REST Framework backend using APIView only for managing Vendors, Products, Courses, Certifications, and hierarchical mappings with validations, Swagger/ReDoc docs, seed data, and tests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages