04. Django Advance - Django Nâng Cao

Mục Tiêu Module

Nắm vững các kỹ thuật Django nâng cao để xây dựng production-ready applications.

Danh Sách Bài Học

1. Advanced Models

  • Model inheritance (Abstract, Multi-table, Proxy)
  • Model Managers
  • Custom QuerySets
  • Model methods và properties
  • Signals (pre_save, post_save, etc.)
  • Model validation

2. Advanced QuerySets

  • select_related() và prefetch_related()
  • annotate() và aggregate()
  • F() và Q() objects
  • Subqueries
  • Raw SQL queries
  • Query optimization

3. Class-Based Views Deep Dive

  • CBV structure
  • Mixins
  • Method overriding
  • Context data
  • Form handling trong CBVs
  • Custom CBVs

4. Django REST Framework - Introduction

  • DRF installation và setup
  • Serializers
  • APIView và ViewSets
  • Routers
  • Request và Response objects

5. DRF Serializers

  • Serializer fields
  • ModelSerializer
  • Nested serializers
  • SerializerMethodField
  • Validation
  • Custom serializers

6. DRF Views và ViewSets

  • APIView
  • GenericAPIView
  • Mixins
  • ViewSets
  • ModelViewSet
  • ReadOnlyModelViewSet

7. DRF Authentication

  • TokenAuthentication
  • SessionAuthentication
  • JWT authentication (simplejwt)
  • Custom authentication
  • Permissions
  • IsAuthenticated, IsAdminUser, etc.

8. DRF Permissions

  • Permission classes
  • Custom permissions
  • Object-level permissions
  • DjangoModelPermissions
  • Permission combinations

9. DRF Pagination

  • PageNumberPagination
  • LimitOffsetPagination
  • CursorPagination
  • Custom pagination
  • DjangoFilterBackend
  • SearchFilter
  • OrderingFilter
  • django-filter integration
  • Custom filters

11. File Uploads

  • FileField và ImageField
  • Handling uploads
  • Media files configuration
  • Pillow library
  • File validation
  • Cloud storage (S3)

12. Email Sending

  • SMTP configuration
  • send_mail() function
  • EmailMessage class
  • HTML emails
  • Email templates
  • Attachments
  • Email backends

13. Caching

  • Cache framework
  • Cache backends (Redis, Memcached)
  • Per-view caching
  • Template fragment caching
  • Low-level cache API
  • Cache strategies

14. Celery Integration

  • Celery installation
  • Message brokers (Redis, RabbitMQ)
  • Defining tasks
  • Calling tasks (delay, apply_async)
  • Periodic tasks (Celery Beat)
  • Task monitoring

15. Advanced Authentication

  • Custom User model
  • Extended User profile
  • Social authentication (OAuth)
  • Multi-factor authentication
  • JWT refresh tokens
  • Token blacklisting

16. Django Channels (WebSockets)

  • Real-time applications
  • ASGI vs WSGI
  • Channels installation
  • Consumers
  • Routing
  • Channel layers

17. Testing Advanced

  • Factory Boy
  • Faker
  • Test fixtures
  • Mocking
  • API testing
  • Coverage reports
  • CI/CD testing

18. Security

  • CSRF protection
  • XSS prevention
  • SQL injection prevention
  • Clickjacking protection
  • HTTPS và SSL
  • Security middleware
  • django-cors-headers

19. Performance Optimization

  • Database query optimization
  • Indexing
  • Connection pooling
  • Caching strategies
  • Lazy loading
  • Debug toolbar
  • Profiling

20. Logging và Monitoring

  • Django logging configuration
  • Log handlers
  • Log formatters
  • Error tracking (Sentry)
  • Application monitoring
  • Performance monitoring

21. Deployment Preparation

  • Environment variables
  • settings.py cho production
  • Static files (collectstatic, WhiteNoise)
  • Database optimization
  • Security checklist
  • ALLOWED_HOSTS

22. Docker Basics

  • Docker concepts
  • Dockerfile
  • Docker Compose
  • Container networking
  • Volumes
  • Multi-stage builds

23. Database Advanced

  • Database transactions
  • select_for_update()
  • Database routers
  • Multiple databases
  • Read replicas
  • Connection pooling

24. Custom Management Commands

  • Creating management commands
  • Command arguments
  • Options
  • Helper methods
  • Use cases

25. Django Third-Party Packages

  • django-extensions
  • django-debug-toolbar
  • django-crispy-forms
  • django-filter
  • django-storages
  • Evaluation criteria

Prerequisites

  • ✅ Hoàn thành Module 03: Django Basic
  • ✅ Hiểu về REST APIs
  • Kiến thức về Docker (cơ bản)
  • Kiến thức về PostgreSQL

Thời Gian Học

  • Ước tính: 4-5 tuần
  • Thời lượng mỗi bài: 90-120 phút
  • Thực hành: 3-4 giờ/ngày

Tài Nguyên Tham Khảo

Projects

Mini Projects

  1. Blog API: RESTful API với DRF
  2. Chat Application: Real-time chat với Channels
  3. Task Queue: Background tasks với Celery

Final Project

E-commerce API Backend:

  • User authentication (JWT)
  • Product catalog với images
  • Shopping cart
  • Order processing
  • Payment integration (mock)
  • Email notifications
  • Celery tasks
  • Caching
  • API documentation
  • Docker deployment

Bài Tập

Mỗi bài học sẽ có:

  • ✍️ Advanced Exercises: 5-8 bài tập phức tạp
  • 🏗️ Architecture Tasks: Thiết kế hệ thống
  • 🧪 Testing Tasks: Viết tests
  • 📝 Quiz: Kiểm tra nâng cao
  • 🚀 Performance Tasks: Optimization

Module Tiếp Theo

05-django-project - Áp dụng kiến thức để xây dựng dự án microservices thực tế.