← Back to the catalog 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.
View on GitHub ↗ Copy repo URL Copy SKILL.md link License: MIT /plugin marketplace add OrcaQubits/agentic-commerce-skills-plugins The exact command may vary by repository. Check the README on GitHub.
For the skill author
Shows your skill is listed on Skillteca, generates a backlink and trackable traffic.
Markdown HTML
[](https://www.skillteca.com.br/skills/python-django?utm_source=badge&utm_medium=readme&utm_campaign=badge) Copy snippet Creates original algorithmic art using p5.js, seeded randomness, and interactive parameter exploration. Use this for requests involving generative art, flow fields, or particle systems, ensuring no copyright infringement.
Escrita e Conteúdo by anthropics
Guides users through a structured workflow for co-authoring documentation, proposals, technical specs, and similar content. It helps efficiently transfer context, refine content through iteration, and verify its effectiveness for readers.
Escrita e Conteúdo by anthropics
This skill enforces Sentry's blog writing standards across every post — whether you're helping an engineer write their first blog post or a marketer draft a product announcement.
Escrita e Conteúdo #github #git by sickn33
This skill should be used when the user asks to "create AGENTS.md", "update AGENTS.md", "maintain agent docs", "set up CLAUDE.md", or needs to keep agent instructions concise. Enforces research-backed best practices for minimal, high-signal agent documentation.
Escrita e Conteúdo #github #git by sickn33
Category alert
One short email with only the new Escrita e Conteúdo skills. 4 minutes of reading, no spam, unsubscribe with one click.
You confirm your email on the first send. No spam. Unsubscribe with one click.
Python & Django for Saleor
Before writing code
Fetch live docs :
Web-search site:docs.djangoproject.com topics models querysets for current Django ORM documentation
Web-search site:docs.djangoproject.com topics signals for Django signals reference
Web-search site:docs.celeryq.dev userguide tasks for Celery task patterns and configuration
Web-search site:docs.saleor.io developer for Saleor-specific Django conventions
Fetch https://docs.python.org/3/library/typing.html for Python type hints reference
Django ORM Patterns for Saleor
QuerySet Operations
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
F and Q Objects
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")
Use F() for atomic field updates without race conditions
Combine Q() objects with | (OR), & (AND), ~ (NOT) for complex filters
Model Relationships in Saleor
Relationship Field Type Example One-to-Many ForeignKeyOrder -> User, OrderLine -> Order Many-to-Many ManyToManyFieldProduct -> Category (via ProductCategory) One-to-One OneToOneFieldUser -> UserProfile Generic GenericForeignKeyAttribute values on multiple entity types
Always set on_delete explicitly (CASCADE, PROTECT, SET_NULL)
Use related_name for reverse lookups
Index foreign keys used in frequent queries
Django Signals
Signal Fires When Common Use pre_saveBefore model.save() Validate or transform data post_saveAfter model.save() Trigger side effects, send notifications pre_deleteBefore model.delete() Clean up related resources post_deleteAfter model.delete() Remove cached data m2m_changedMany-to-many field modified Update denormalized counters
Saleor uses webhooks as the primary event mechanism, not Django signals
Use signals sparingly for internal side effects only
Never perform expensive I/O in signal handlers (use Celery tasks instead)
Connect signals in AppConfig.ready() to avoid import issues
Celery Task Patterns
Defining Tasks
Pattern Decorator Use Case Shared task @shared_taskFramework-agnostic, recommended App task @app.taskTied to specific Celery app Bound task @shared_task(bind=True)Access self for retries
Retry and Error Handling
Parameter Description Example max_retriesMaximum retry attempts 3default_retry_delaySeconds between retries 60retry_backoffEnable exponential backoff Trueautoretry_forException classes to auto-retry (ConnectionError,)acks_lateAcknowledge after execution True (prevents task loss)
Pass serializable arguments (IDs, not model instances)
Keep tasks idempotent — safe to retry without side effects
Set reasonable timeouts with soft_time_limit and time_limit
Python Type Hints
Type Import Use Optional[T]typingValue may be None list[T]Built-in (3.9+) Typed list dict[K, V]Built-in (3.9+) Typed dictionary Union[A, B]typingEither type A or B ProtocoltypingStructural subtyping (duck typing) TypedDicttypingTyped dictionary with fixed keys Literal["a", "b"]typingRestrict to specific values
Use from __future__ import annotations for postponed evaluation
Type all function parameters, return values, and class attributes
Use mypy or pyright for static type checking
Database Migrations
Command Purpose python manage.py makemigrationsGenerate migration files from model changes python manage.py migrateApply pending migrations to database python manage.py showmigrationsList all migrations and their status python manage.py sqlmigrate app_name 0001Show SQL for a specific migration python manage.py squashmigrations app_name 0001 0010Combine multiple migrations
Review generated migrations before applying to production
Use RunPython for data migrations (separate from schema migrations)
Test migrations on a copy of production data before deploying
Management Commands
Aspect Convention Location app_name/management/commands/command_name.pyClass Subclass BaseCommand Entry point handle(self, *args, **options) methodArguments Use add_arguments(self, parser) with argparse Output Use self.stdout.write() and self.style
Use management commands for one-off scripts, data fixes, and admin tasks
Always add help text to commands for documentation
Async Django Views (ASGI)
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 requestshttpx (async)
Saleor runs via ASGI with Uvicorn workers under Gunicorn
Django ORM is synchronous — use sync_to_async or QuerySet.aiterator()
Use httpx.AsyncClient for non-blocking HTTP requests
Django Settings and Virtual Environments
Pattern Description Environment variables Load with os.environ or django-environ Split settings settings/base.py, settings/dev.py, settings/prod.pyTwelve-Factor All configuration via environment variables
Tool Command Notes venv python -m venv .venvBuilt-in, standard poetry poetry installDependency resolution, lock file uv uv venv && uv pip install -r requirements.txtFast Rust-based installer
Best Practices
Use select_related and prefetch_related to avoid N+1 query problems
Keep Django signals lightweight — offload heavy work to Celery tasks
Type all function signatures and use mypy for static analysis
Make Celery tasks idempotent and pass only serializable arguments
Review migration SQL before applying to production databases
Use F() expressions for atomic field updates instead of read-modify-write
Follow Saleor's existing code style when contributing to the core
Use async views and httpx for I/O-heavy endpoints
Store all configuration in environment variables following twelve-factor methodology
Fetch the Python and Django documentation for current ORM patterns, Celery task configuration, and async view setup before implementing.
Read full description↓
Comments · No comments No comments yet. Be the first.