djangopatterns
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "djangopatterns" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-c39d133633dba111e26ea7c5b64f5875af2e17c383049e62fdf844750bf25e97. Verify the upstream source and version against https://skillhub.cn/skills/user_3c6cb52e/django-patterns-48b8 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Skill for DjangoPatterns to help an AI agent efficiently complete tasks and handle issues related to DjangoPatterns.
Introduction source: third_party · user_3c6cb52e · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Organize Django projects with a clear separation between apps, shared utilities, and configuration.
- Audience
- Not specified in the source documentation.
- Inputs and outputs
- Not specified in the source documentation.
- Software, accounts and paid services
- Not specified in the source documentation.
- Limits and differences
- Not specified in the source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: Djangopatterns
slug: django-patterns
version: 1.0.0
displayName: Djangopatterns
description: >
DjangoPatterns专用技能,帮助AI Agent高效完成相关任务。
summary: "DjangoPatterns专用技能,帮助AI Agent高效完成相关任务。"
license: MIT
category: 开发者工具
framework:
- Claude Code
- Codex
- Hermes Agent
- OpenClaw
- QClaw
- WorkBuddy
platform: multi-platform
homepage: "https://github.com/1991513ccie-png"
repository: "https://github.com/1991513ccie-png"Django Patterns
Project Structure
Organize Django projects with a clear separation between apps, shared utilities, and configuration.
project/
config/
settings/
base.py
local.py
production.py
urls.py
wsgi.py
apps/
users/
models.py
serializers.py
views.py
services.py
selectors.py
urls.py
tests/
orders/
...
common/
models.py
permissions.py
pagination.py
Keep business logic in services.py (write operations) and selectors.py (read operations). Views should remain thin.
ORM Optimization
# select_related for ForeignKey / OneToOne (SQL JOIN)
orders = Order.objects.select_related("customer", "customer__profile").all()
# prefetch_related for ManyToMany / reverse FK (separate query)
authors = Author.objects.prefetch_related(
Prefetch("books", queryset=Book.objects.filter(published=True))
).all()
# Defer fields you don't need
posts = Post.objects.defer("body", "metadata").filter(status="published")
# Use .only() when you need just a few columns
emails = User.objects.only("id", "email").filter(is_active=True)
# Bulk operations
Product.objects.bulk_create(products, batch_size=1000)
Product.objects.bulk_update(products, ["price", "stock"], batch_size=1000)
Always check queries with django-debug-toolbar or connection.queries in tests.
Django REST Framework Serializers
class OrderSerializer(serializers.ModelSerializer):
customer_name = serializers.CharField(source="customer.full_name", read_only=True)
items = OrderItemSerializer(many=True, read_only=True)
total = serializers.SerializerMethodField()
class Meta:
model = Order
fields = ["id", "customer_name", "items", "total", "created_at"]
read_only_fields = ["id", "created_at"]
def get_total(self, obj):
return sum(item.price * item.quantity for item in obj.items.all())
def validate(self, data):
if data.get("start_date") and data.get("end_date"):
if data["start_date"] >= data["end_date"]:
raise serializers.ValidationError("end_date must be after start_date")
return data
Signals
from django.db.models.signals import post_save
from django.dispatch import receiver
@receiver(post_save, sender=Order)
def order_created_handler(sender, instance, created, **kwargs):
if created:
send_order_confirmation.delay(instance.id)
update_inventory.delay(instance.id)
Prefer signals for cross-app side effects. For same-app logic, call services directly.
Custom Middleware
import time
import logging
logger = logging.getLogger(__name__)
class RequestTimingMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
start = time.monotonic()
response = self.get_response(request)
duration = time.monotonic() - start
logger.info(f"{request.method} {request.path} {response.status_code} {duration:.3f}s")
return response
Anti-Patterns
- Putting business logic in views or serializers instead of service layers
- Using
Model.objects.all()without pagination in list endpoints - N+1 queries from missing
select_related/prefetch_related - Overusing signals for same-app logic (makes flow hard to trace)
- Storing secrets in
settings.pyinstead of environment variables - Running raw SQL without parameterized queries
Checklist
- [ ] Business logic lives in services/selectors, not views
- [ ] All list queries use
select_relatedorprefetch_relatedwhere needed - [ ] Serializers validate input data with custom
validatemethods - [ ] Settings split into base/local/production modules
- [ ] Migrations are reviewed before merging
- [ ] Bulk operations used for batch inserts/updates
- [ ] Custom middleware follows the WSGI callable pattern
- [ ] Tests cover model constraints, serializer validation, and view permissions
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 Django 项目结构、ORM 优化、DRF 序列化器、信号、中间件等实用开发模式
- 面向开发者群体,解决实际开发痛点,具有明确的实用价值
Highlights
- 触发词描述清晰完整,边界明确,针对 Django 开发者场景
Highlights
- 结构完整,包含多个清晰章节和端到端代码示例
- frontmatter 信息完整,Checklist 提供明确验收标准
Highlights
- 所有代码示例均为标准 Django/DRF 语法,参数使用正确
- Anti-Patterns 和 Checklist 有效覆盖常见陷阱和验证点
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- github.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Not specified in the source documentation.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.