Skip to content

Django — Advanced (50+ Coding Exercises)

  1. Implement an idempotency key model and middleware to enforce idempotent POST requests.
  2. Implement F()-expression based atomic counter increment endpoint.
  3. Implement a wallet transfer flow with transaction.atomic() and DB constraints to prevent double-spend.
  4. Add optimistic locking using a version integer field; reject updates when version mismatches.
  5. Add pessimistic locking using select_for_update() in a critical section.
  6. Implement object-level permissions for Project model (owner + collaborators).
  7. Implement a custom auth backend that authenticates via API token header.
  8. Implement a custom user model using email as username; migrate from default (new project approach).
  9. Implement a multi-tenant middleware that selects tenant via subdomain and stores it in request.
  10. Implement tenant-aware QuerySet filtering via custom model manager.
  11. Implement database router skeleton for multiple DBs (reads to replica, writes to primary).
  12. Implement a zero-downtime migration plan for adding non-null column (two-step migration + backfill command).
  13. Implement a data backfill management command with progress output and batching.
  14. Implement a generic comments system using contenttypes and GenericForeignKey.
  15. Implement a tagging system reusable across models (generic M2M via through model).
  16. Implement deep prefetch_related optimization for a complex page and assert query count in tests.
  17. Implement a cache invalidation strategy: delete relevant cache keys on model save/delete.
  18. Implement stampede protection for expensive cache fills using a lock key in cache.
  19. Implement CSP header injection middleware with configurable policy.
  20. Implement secure file upload validation (extension + content sniffing) and store outside web root.
  21. Implement direct-to-S3 upload design: create signed URL endpoint and callback verification (code skeleton).
  22. Implement login rate limiting using cache counters and exponential backoff lockouts.
  23. Implement request tracing: add request ID middleware + structured logging format.
  24. Implement metrics endpoint (simple counters) and measure request latency buckets (code skeleton).
  25. Implement Celery task skeleton with retries and dead-letter handling strategy.
  26. Implement periodic task schedule configuration (Celery beat or crontab-like).
  27. Implement a real-time notifications proof-of-concept using Django Channels (routing + consumer skeleton).
  28. Implement Server-Sent Events endpoint for streaming progress of a long task (ASGI).
  29. Implement graceful shutdown handling for long-running requests (timeouts + cancellation awareness).
  30. Implement an audit log model that records create/update/delete for important models.
  31. Implement an admin interface for audit logs with filters and search.
  32. Implement “soft delete” across multiple models using an abstract base model + manager.
  33. Implement GDPR-like data export for a user (collect related models into JSON).
  34. Implement GDPR-like delete/anonymize job for a user (background task).
  35. Implement a plugin-style “service layer” pattern for side effects instead of signals.
  36. Refactor an existing signal side-effect into a service function and update call sites.
  37. Implement per-object access checks in class-based views with a reusable mixin.
  38. Implement DRY API error format for JSON responses (custom exception + handler).
  39. Implement request/response logging with PII redaction (email, token) middleware.
  40. Implement a safe settings loader reading secrets from env and failing fast if missing.
  41. Implement a health check endpoint that verifies DB and cache connectivity.
  42. Implement a readiness endpoint for Kubernetes style deployments (db migrations applied check).
  43. Implement blue/green deploy checklist as a management command that runs validations.
  44. Implement database query profiling toggle that logs slow queries above threshold.
  45. Implement a “maintenance mode” middleware that serves 503 except for admins.
  46. Implement a file cleanup cron/command that removes orphaned media files.
  47. Implement a robust pagination API with cursor-based pagination.
  48. Implement a queryset permission filter that restricts rows based on user role and tenant.
  49. Implement integration tests for multi-tenant routing and permissions.
  50. Implement load-test friendly endpoint behavior (timeouts, limits) and add tests for max page size.
  51. Implement a safe bulk update API that validates fields and uses bulk_update.
  52. Implement a “rebuild search index” command for a simple text index table.