Install the skill above, then run this in your AI tool:
/django-patterns <your description>
About
Production-grade Django architecture patterns for scalable, maintainable applications.
Source
What gets added to your project
Preview every file this package writes on install before you run the command above.
Summary
Django architecture patterns, REST API design with DRF, ORM best practices, caching, signals, middleware, and production-grade Django apps. Use when building or reviewing Django apps, DRF APIs, ORM queries, or caching.
Skill instructions
Django Development Patterns
Production-grade Django architecture patterns for scalable, maintainable applications.
# apps/users/signals.pyfrom django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth import get_user_model
from .models import Profile
User = get_user_model()
@receiver(post_save, sender=User)defcreate_user_profile(sender, instance, created, **kwargs):
"""Create profile when user is created."""if created:
Profile.objects.create(user=instance)
@receiver(post_save, sender=User)defsave_user_profile(sender, instance, **kwargs):
"""Save profile when user is saved."""
instance.profile.save()
# apps/users/apps.pyfrom django.apps import AppConfig
classUsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.users'defready(self):
"""Import signals when app is ready."""import apps.users.signals
Middleware
Custom Middleware
python
# middleware/active_user_middleware.pyimport time
from django.utils.deprecation import MiddlewareMixin
classActiveUserMiddleware(MiddlewareMixin):
"""Middleware to track active users."""defprocess_request(self, request):
"""Process incoming request."""if request.user.is_authenticated:
# Update last active time
request.user.last_active = timezone.now()
request.user.save(update_fields=['last_active'])
classRequestLoggingMiddleware(MiddlewareMixin):
"""Middleware for logging requests."""defprocess_request(self, request):
"""Log request start time."""
request.start_time = time.time()
defprocess_response(self, request, response):
"""Log request duration."""ifhasattr(request, 'start_time'):
duration = time.time() - request.start_time
logger.info(f'{request.method}{request.path} - {response.status_code} - {duration:.3f}s')
return response
Performance Optimization
N+1 Query Prevention
python
# Bad - N+1 queries
products = Product.objects.all()
for product in products:
print(product.category.name) # Separate query for each product# Good - Single query with select_related
products = Product.objects.select_related('category').all()
for product in products:
print(product.category.name)
# Good - Prefetch for many-to-many
products = Product.objects.prefetch_related('tags').all()
for product in products:
for tag in product.tags.all():
print(tag.name)
# Bulk create
Product.objects.bulk_create([
Product(name=f'Product {i}', price=10.00)
for i inrange(1000)
])
# Bulk update
products = Product.objects.all()[:100]
for product in products:
product.is_active = True
Product.objects.bulk_update(products, ['is_active'])
# Bulk delete
Product.objects.filter(stock=0).delete()
Quick Reference
Pattern
Description
Split settings
Separate dev/prod/test settings
Custom QuerySet
Reusable query methods
Service Layer
Business logic separation
ViewSet
REST API endpoints
Serializer validation
Request/response transformation
select_related
Foreign key optimization
prefetch_related
Many-to-many optimization
Cache first
Cache expensive operations
Signals
Event-driven actions
Middleware
Request/response processing
Remember: Django provides many shortcuts, but for production applications, structure and organization matter more than concise code. Build for maintainability.
Add this badge to a GitHub README so readers can open the package page and install the same version.
[](https://www.aipm-registry.com/skills/affaan-m/django-patterns/1.0.0?utm_source=github&utm_medium=readme&utm_campaign=package_badge)
This imported publisher has not claimed its AIPM account. A connected account confirms account control, but it does not guarantee that a package is safe.
AI assistant context
What this skill is for
@affaan-m/django-patterns@1.0.0 is an AIPM skill package for All tools. Use it when a project needs the reusable AI behavior described as: Django architecture patterns, REST API design with DRF, ORM best practices, caching, signals, middleware, and production-grade Django apps. Use when building or reviewing Django apps, DRF APIs, ORM queries, or caching.
Vite build tool patterns including config, plugins, HMR, env variables, proxy setup, SSR, library mode, dependency pre-bundling, and build optimization. Activate when working with vite.config.ts, Vite plugins, or Vite-based projects.
Translate visa document images (bank deposit, employment, income, and retirement certificates; HEIC, PNG, or JPG) into English via OCR and produce a bilingual PDF pairing the original image with a formatted certified-style translation. U...
Ingest, index, search, edit, and monitor video and audio with the VideoDB Python SDK — upload from files, URLs, or RTSP feeds, build spoken and scene indexes with timestamped search and playable clips, transcode and reframe, do timeline...
Run aipm add @affaan-m/django-patterns@1.0.0 in a project that has AIPM initialized.
Supported tools
@affaan-m/django-patterns@1.0.0 supports All tools.
Before installing
AIPM skills can add files to your project. Review the package name, target, description, license, and publisher before installing. Use a clean branch when trying a new skill.