django-orm-patterns

django-orm-patterns is a skill for Claude Code from AratKruglik/claude-sdlc. It costs 202 tokens per session (2,238 once invoked), scanned A, original, MIT.

A guide to Django's object-relational mapper, the part of Django that represents database tables as Python classes and builds database queries. It covers models, reusable query methods, transactions, relationships, indexes, and constraints.

In plain words
What is it for?
Use it to define Django models, choose field types, add ordering and validation rules, write reusable queries, manage transactions, and prevent repeated database queries.
Why use it?
It helps developers write database code that is correct and avoids slow patterns such as making one extra query for every returned record.

Skill for Claude Code

Written for Claude Code: user-invocable in frontmatter.

Part of the django-plugin plugin — 2 skills, 2 agents shipped together

Good fit Use it to define Django models, choose field types, add ordering and validation rules, write reusable queries, manage transactions, and prevent repeated database queries.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/aratkruglik/claude-sdlc/django-orm-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add AratKruglik/claude-sdlc --skill django-orm-patterns
Clone the repo
git clone --depth 1 https://github.com/AratKruglik/claude-sdlc

Made for: Claude Code.

Or install django-plugin, the plugin that ships this one along with the rest of its 2 skills, 2 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for django-orm-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/django-orm-patterns/github.svg)](https://agentmods.dev/skills/aratkruglik/claude-sdlc/django-orm-patterns)
Your own site
<a href="https://agentmods.dev/skills/aratkruglik/claude-sdlc/django-orm-patterns"><img src="https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/django-orm-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for django-orm-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/aratkruglik/claude-sdlc/django-orm-patterns"><img src="https://agentmods.dev/badge/skills/aratkruglik/claude-sdlc/django-orm-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 202 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,238 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00202 $0.02238
Opus 5.5 $0.00081 $0.00895
Sonnet 5.5 $0.00040 $0.00448
Haiku 4.5 $0.00020 $0.00224

Measured 1mo ago against content hash 7a68e8880d72, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

django-orm-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/django-plugin/skills/django-orm-patterns/SKILL.md · 272 lines

How it starts

The opening of the file, as written. The whole thing — 272 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Django ORM Patterns

This skill covers Django ORM model definitions, query patterns, and database-level options. Apply alongside django-plugin:django-conventions when implementing features.

Role split:

  • django-architect uses this skill for model definitions — fields, __str__, choices, class Meta ordering, custom managers, and query patterns.
  • django-migrations-specialist uses this skill for field finalization — setting max_digits, on_delete, db_index, Meta.indexes, Meta.constraints — before running makemigrations.

1. Detection

Check the Django version in requirements.txt or pyproject.toml before writing constraint code — Meta.constraints using CheckConstraint uses condition= in Django 5.1+ and check= in Django 4.x. When uncertain, check the installed version with python manage.py --version or read the pinned version from the dependency file.

2. Model definition patterns

Use TextChoices for string-typed status/type fields. Write a meaningful __str__. Always specify class Meta ordering.

from django.db import models
from django.contrib.auth import get_user_model

User = get_user_model()


class Order(models.Model):
    class Status(models.TextChoices):
        PENDING = 'pending', 'Pending'
        PROCESSING = 'processing', 'Processing'
        SHIPPED = 'shipped', 'Shipped'
        CANCELLED = 'cancelled', 'Cancelled'

    user = models.ForeignKey(User, on_delete=models.PROTECT, related_name='orders')
    product = models.CharField(max_length=255)
    qty = models.PositiveIntegerField()
    unit_price = models.DecimalField(max_digits=10, decimal_places=2)
    status = models.CharField(max_length=20, choices=Status.choices, default=Status.PENDING)
    notes = models.TextField(blank=True, default='')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-created_at']
        indexes = [
            models.Index(fields=['status', 'created_at']),
        ]
        constraints = [
            models.UniqueConstraint(fields=['user', 'reference'], name='unique_user_reference'),
            # Django 5.1+: condition=; Django 4.x: check=
            models.CheckConstraint(condition=models.Q(qty__gt=0), name='orders_order_qty_positive'),
        ]

    def __str__(self) -> str:
        return f'Order #{self.pk} — {self.product} ({self.get_status_display()})'

    @property
    def is_cancellable(self) -> bool:
        return self.status in (self.Status.PENDING, self.Status.PROCESSING)

Read the full file on GitHub · 272 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · +2 lines 7a68e8880d72
  2. 1mo ago First seen · 270 lines · 202 tokens per session scan A bb208677996d

Subscribe to this mod's changes

django-orm-patterns is a skill published in the GitHub repository AratKruglik/claude-sdlc (49 stars, last pushed yesterday), licensed MIT. It adds 202 tokens to every session and 2,238 once invoked, about $0.0008 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.