django-patterns

Implements production-grade Django architecture patterns for REST APIs, ORM, caching, and middleware.

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill django-patterns-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: django-patterns
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/django-patterns
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill django-patterns-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building maintainable Django applications requires consistent architecture decisions across project structure, models, APIs, and performance optimization. This Skill provides proven patterns that prevent common pitfalls like N+1 queries, unorganized settings, and tangled business logic. ## Core Features & Use Cases - Project Structure & Settings: Split settings pattern for development, production, and test environments with proper security configuration. - DRF API Design: Serializer validation, ViewSet patterns with custom actions, filtering, and permission handling for REST APIs. - ORM & Performance: Custom QuerySets, managers, select_related/prefetch_related optimization, database indexing, and bulk operations. - Use Case: When building a new Django REST API for an e-commerce backend, apply the service layer pattern to keep order-processing business logic out of views, use custom QuerySets to avoid N+1 queries on product listings, and cache expensive category aggregations. ## Quick Start Ask the agent to scaffold a Django project structure with split settings and a DRF ViewSet for a Product model following production patterns.

Frequently Asked Questions about django-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a Django project for production?▼

Use a config package with split settings files (base.py, development.py, production.py, test.py) and place business apps under an apps/ directory. Production settings should enforce DEBUG=False, secure cookies, HSTS, and file-based logging.

How to avoid N+1 queries in Django ORM?▼

Use select_related for foreign key relationships and prefetch_related for many-to-many fields when querying. Encapsulate these in custom QuerySet methods like with_category() so the optimization is applied consistently across the codebase.

What is the service layer pattern in Django?▼

The service layer pattern moves business logic out of views and models into dedicated service classes, such as an OrderService handling order creation and payment processing. This keeps views thin and makes transactional logic with transaction.atomic easier to test.

How do I add custom actions to a DRF ViewSet?▼

Use the @action decorator on ViewSet methods, specifying detail=True for single-object endpoints or detail=False for collection endpoints. You can override permission_classes per action and route them automatically through the DRF router.

When should I use caching in a Django application?▼

Cache expensive operations like aggregated queries or featured product lists using Django's low-level cache API with explicit keys and timeouts. Use per-view caching with cache_page for expensive views and template fragment caching for costly sidebar or partial renders.