django-patterns

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

Updated May 19, 2026
One-click install
npx skills add https://github.com/azusagasaku/--claude-config --skill django-patterns-azusagasaku
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: django-patterns
Source: https://github.com/azusagasaku/--claude-config/tree/main/skills/ecc/django-patterns
Command: npx skills add https://github.com/azusagasaku/--claude-config --skill django-patterns-azusagasaku

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building scalable Django applications requires consistent architectural decisions across project structure, ORM usage, API design, 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 endpoints. - ORM & Performance: Custom QuerySets, managers, select_related/prefetch_related optimization, database indexing, and bulk operations. - Use Case: When building an e-commerce API, apply the service layer pattern to separate order creation logic from views, use custom QuerySets to avoid N+1 queries on product listings, and cache expensive category aggregations. ## Quick Start Use the django-patterns skill to design a REST API for a product catalog with proper serializers, ViewSets, and query optimization.

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 apps in a dedicated apps/ directory. Each app should contain models, views, serializers, services, permissions, and filters modules for clear separation of concerns.

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

Use select_related for foreign key relationships and prefetch_related for many-to-many relationships when querying. Define custom QuerySet methods like with_category() that encapsulate these optimizations so they are 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 in a services.py module. For example, an OrderService handles order creation, payment processing, and email notifications using transaction.atomic for data integrity.

Does Django REST Framework support custom ViewSet actions?▼

Yes, use the @action decorator to add custom endpoints to ViewSets, such as a purchase action on a product or a featured list endpoint. You can specify detail=True for single-object actions and override permission_classes per action.

When should I use Django signals versus overriding save methods?▼

Use signals like post_save for cross-app side effects such as creating a user profile, keeping apps decoupled. Override save() for logic intrinsic to the model itself, like auto-generating a slug from the name field.

How do I cache expensive Django queries?▼

Use Django's low-level cache API with cache.get and cache.set to store query results with a timeout, checking the cache before hitting the database. For simpler cases, apply cache_page decorators to views or cache template fragments with the cache template tag.