dist/cursor/saleor-commerce/skills/python-django/SKILL.md
Write Python and Django code for Saleor — Django ORM patterns, signals, Celery tasks, type hints, migrations, management commands, and async views. Use when writing Python/Django in Saleor projects.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins python-djangoInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Fetch live docs:
site:docs.djangoproject.com topics models querysets for current Django ORM documentationsite:docs.djangoproject.com topics signals for Django signals referencesite:docs.celeryq.dev userguide tasks for Celery task patterns and configurationsite:docs.saleor.io developer for Saleor-specific Django conventionshttps://docs.python.org/3/library/typing.html for Python type hints reference| Operation | Method | Example Use |
|-----------|--------|-------------|
| Filter | .filter(**kwargs) | Filter products by type |
| Exclude | .exclude(**kwargs) | Exclude draft orders |
| Annotate | .annotate(expr) | Add computed fields (totals, counts) |
| Aggregate | .aggregate(expr) | Compute sum, avg across queryset |
| Select related | .select_related("fk") | Join foreign keys (avoid N+1) |
| Prefetch related | .prefetch_related("m2m") | Batch-load many-to-many (avoid N+1) |
| Values | .values("field") | Return dictionaries instead of objects |
| Order by | .order_by("field") | Sort results |
| Object | Purpose | Example Use |
|--------|---------|-------------|
| F("field") | Reference model field in expressions | Update stock: F("quantity") - 1 |
| Q(condition) | Complex lookups with OR/AND/NOT | Q(status="active") | Q(featured=True) |
F() for atomic field updates without race conditionsQ() objects with | (OR), & (AND), ~ (NOT) for complex filters| Relationship | Field Type | Example |
|-------------|-----------|---------|
| One-to-Many | ForeignKey | Order -> User, OrderLine -> Order |
| Many-to-Many | ManyToManyField | Product -> Category (via ProductCategory) |
| One-to-One | OneToOneField | User -> UserProfile |
| Generic | GenericForeignKey | Attribute values on multiple entity types |
on_delete explicitly (CASCADE, PROTECT, SET_NULL)related_name for reverse lookups| Signal | Fires When | Common Use |
|--------|-----------|------------|
| pre_save | Before model.save() | Validate or transform data |
| post_save | After model.save() | Trigger side effects, send notifications |
| pre_delete | Before model.delete() | Clean up related resources |
| post_delete | After model.delete() | Remove cached data |
| m2m_changed | Many-to-many field modified | Update denormalized counters |
AppConfig.ready() to avoid import issues| Pattern | Decorator | Use Case |
|---------|-----------|----------|
| Shared task | @shared_task | Framework-agnostic, recommended |
| App task | @app.task | Tied to specific Celery app |
| Bound task | @shared_task(bind=True) | Access self for retries |
| Parameter | Description | Example |
|-----------|-------------|---------|
| max_retries | Maximum retry attempts | 3 |
| default_retry_delay | Seconds between retries | 60 |
| retry_backoff | Enable exponential backoff | True |
| autoretry_for | Exception classes to auto-retry | (ConnectionError,) |
| acks_late | Acknowledge after execution | True (prevents task loss) |
soft_time_limit and time_limit| Type | Import | Use |
|------|--------|-----|
| Optional[T] | typing | Value may be None |
| list[T] | Built-in (3.9+) | Typed list |
| dict[K, V] | Built-in (3.9+) | Typed dictionary |
| Union[A, B] | typing | Either type A or B |
| Protocol | typing | Structural subtyping (duck typing) |
| TypedDict | typing | Typed dictionary with fixed keys |
| Literal["a", "b"] | typing | Restrict to specific values |
from __future__ import annotations for postponed evaluationmypy or pyright for static type checking| Command | Purpose |
|---------|---------|
| python manage.py makemigrations | Generate migration files from model changes |
| python manage.py migrate | Apply pending migrations to database |
| python manage.py showmigrations | List all migrations and their status |
| python manage.py sqlmigrate app_name 0001 | Show SQL for a specific migration |
| python manage.py squashmigrations app_name 0001 0010 | Combine multiple migrations |
RunPython for data migrations (separate from schema migrations)| Aspect | Convention |
|--------|-----------|
| Location | app_name/management/commands/command_name.py |
| Class | Subclass BaseCommand |
| Entry point | handle(self, *args, **options) method |
| Arguments | Use add_arguments(self, parser) with argparse |
| Output | Use self.stdout.write() and self.style |
help text to commands for documentation| Feature | Sync | Async |
|---------|------|-------|
| View type | def view(request) | async def view(request) |
| Server | WSGI (Gunicorn) | ASGI (Uvicorn, Daphne) |
| ORM access | Direct | Wrap in sync_to_async |
| HTTP calls | requests | httpx (async) |
sync_to_async or QuerySet.aiterator()httpx.AsyncClient for non-blocking HTTP requests| Pattern | Description |
|---------|-------------|
| Environment variables | Load with os.environ or django-environ |
| Split settings | settings/base.py, settings/dev.py, settings/prod.py |
| Twelve-Factor | All configuration via environment variables |
| Tool | Command | Notes |
|------|---------|-------|
| venv | python -m venv .venv | Built-in, standard |
| poetry | poetry install | Dependency resolution, lock file |
| uv | uv venv && uv pip install -r requirements.txt | Fast Rust-based installer |
select_related and prefetch_related to avoid N+1 query problemsmypy for static analysisF() expressions for atomic field updates instead of read-modify-writehttpx for I/O-heavy endpointsFetch the Python and Django documentation for current ORM patterns, Celery task configuration, and async view setup before implementing.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.