0–5 min
Real Hook
5–25 min
Core Concept
25–45 min
Live Coding
45–55 min
You Code It
55–60 min
Cheat Sheet
🔥 Real-World Hook (0–5 min)
This is interview day. Build a full product from scratch — just like your first week at a company.
You get a requirements doc. No step-by-step instructions. You decide the models, the API design, and the UI. The instructor is the "client". This is what they test at Amazon, Flipkart, and every Indian startup: can you turn requirements into a working system?
📝 Requirements: Library Book Tracker (5–25 min)
💡 What to Build
Models: Book (title, author, isbn, available_copies), Member (name, email, membership_id), Borrow (book FK, member FK, borrowed_on, due_date, returned)
API: CRUD for books and members. POST /api/borrows/ to borrow a book (decrements available_copies). POST /api/returns/ to return (increments).
Frontend: Book list with available count. Borrow form. Member dashboard showing active borrows.
📊 Architecture First (25–45 min)
# models.py — design before you code
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=100)
isbn = models.CharField(max_length=13, unique=True)
available_copies = models.IntegerField(default=1)
class Member(models.Model):
name = models.CharField(max_length=100)
email = models.EmailField(unique=True)
membership_id = models.CharField(max_length=20, unique=True)
class Borrow(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
member = models.ForeignKey(Member, on_delete=models.CASCADE)
borrowed_on = models.DateField(auto_now_add=True)
due_date = models.DateField()
returned = models.BooleanField(default=False)
# Custom ViewSet action for borrowing
from rest_framework.decorators import action
from rest_framework.response import Response
from django.utils import timezone
from datetime import timedelta
class BorrowViewSet(viewsets.ModelViewSet):
queryset = Borrow.objects.all()
serializer_class = BorrowSerializer
@action(detail=False, methods=["post"])
def borrow_book(self, request):
book = Book.objects.get(pk=request.data["book_id"])
if book.available_copies < 1:
return Response({"error": "No copies available"}, status=400)
book.available_copies -= 1
book.save()
borrow = Borrow.objects.create(
book=book,
member_id=request.data["member_id"],
due_date=timezone.now().date() + timedelta(days=14)
)
return Response(BorrowSerializer(borrow).data, status=201)
🎯 You Code It — Build It Solo (45–55 min)
- Set up project, create models, run migrations
- Create serializers for Book, Member, Borrow
- Wire up CRUD ViewSets + the custom
borrow_book action
- Add the return action: marks returned=True, increments available_copies
- Build a simple HTML page: show book list with available count
- Test full flow: add book, add member, borrow, return — watch available_copies change
- Show: Running demo end-to-end. Explain every model decision.
📄 Day 12 Cheat Sheet — ForeignKey & Custom Actions
ForeignKey
| ForeignKey(Model, on_delete=CASCADE) | Required FK |
| on_delete=SET_NULL, null=True | Optional FK |
| obj.related_model | Access related object |
| book.borrow_set.all() | Reverse relation |
| select_related("book") | JOIN to avoid N+1 |
Custom Actions
| @action(detail=False, methods=["post"]) | List action |
| @action(detail=True, methods=["post"]) | Detail action |
| return Response(data, status=201) | Return JSON |
| from rest_framework import status | Status constants |
Date / Time
| from django.utils import timezone | Import |
| timezone.now() | Current datetime |
| timezone.now().date() | Today's date |
| from datetime import timedelta | Import timedelta |
| date + timedelta(days=14) | 2 weeks from now |
Validation Pattern
| serializer.is_valid(raise_exception=True) | Auto 400 on fail |
| serializer.validated_data | Clean data |
| raise serializers.ValidationError | Custom error |
| def validate_field(self, value): | Field-level validator |