django-orm-mastery

django-orm-mastery is a skill for Claude Code from VersoXBT/claude-initial-setup. It costs 71 tokens per session (1,907 once invoked), scanned A, original, MIT.

A guide to writing database queries with Django's built-in Python database layer, called the Django ORM. It covers filtering, related records, calculations, and safely using SQL when needed.

In plain words
What is it for?
Use it to build and optimize Django queries, fetch related data efficiently, and perform filtering, counting, grouping, and aggregation.
Why use it?
It helps avoid slow queries and the N+1 problem, where one request causes a separate database query for every related item.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the claude-initial-setup plugin — 75 skills, 15 commands, 14 agents, 2 hooks shipped together

Good fit Use it to build and optimize Django queries, fetch related data efficiently, and perform filtering, counting, grouping, and aggregation.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/versoxbt/claude-initial-setup/django-orm-mastery
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 VersoXBT/claude-initial-setup --skill django-orm-mastery
Clone the repo
git clone --depth 1 https://github.com/VersoXBT/claude-initial-setup

Made for: Claude Code.

Or install claude-initial-setup, the plugin that ships this one along with the rest of its 75 skills, 15 commands, 14 agents, 2 hooks.

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-mastery

README.md
[![agentmods](https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/django-orm-mastery/github.svg)](https://agentmods.dev/skills/versoxbt/claude-initial-setup/django-orm-mastery)
Your own site
<a href="https://agentmods.dev/skills/versoxbt/claude-initial-setup/django-orm-mastery"><img src="https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/django-orm-mastery/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-mastery

Your own site · 80×15
<a href="https://agentmods.dev/skills/versoxbt/claude-initial-setup/django-orm-mastery"><img src="https://agentmods.dev/badge/skills/versoxbt/claude-initial-setup/django-orm-mastery.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 71 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,907 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.
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.00071 $0.01907
Opus 5.5 $0.00028 $0.00763
Sonnet 5.5 $0.00014 $0.00381
Haiku 4.5 $0.00007 $0.00191

Measured 1mo ago against content hash 4e51fad450da, 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-mastery 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.

skills/django/django-orm-mastery/SKILL.md · 269 lines

How it starts

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

Django ORM Mastery

Write efficient, expressive Django ORM queries. The ORM is lazy by default -- QuerySets are not evaluated until iterated. Understanding this is key to avoiding N+1 queries and building performant applications.

When to Use

  • User writes Django model queries
  • User encounters slow queries or N+1 problems
  • User needs complex filtering, aggregation, or annotation
  • User asks about select_related vs prefetch_related
  • User needs database-level operations without pulling data into Python

Core Patterns

QuerySet Basics and Chaining

QuerySets are lazy -- they build SQL without executing until evaluated. Chain freely.

# Lazy -- no SQL executed yet
qs = (
    Article.objects
    .filter(status="published")
    .exclude(category__name="draft")
    .order_by("-published_at")
)

# SQL executes when you iterate, slice, call list(), len(), bool(), etc.
articles = list(qs[:10])

# Efficient existence check -- use .exists() not len() or bool()
if Article.objects.filter(slug=slug).exists():
    raise ValidationError("Slug already taken")

# Efficient count -- use .count() not len(qs)
total = Article.objects.filter(status="published").count()

# Get or 404
from django.shortcuts import get_object_or_404
article = get_object_or_404(Article, slug=slug, status="published")

select_related (ForeignKey / OneToOne)

Performs a SQL JOIN. Use for ForeignKey and OneToOneField relationships. Fetches related objects in a single query.

# WITHOUT select_related -- N+1 problem
articles = Article.objects.all()
for article in articles:
    print(article.author.name)  # Each access hits the database

# WITH select_related -- single JOIN query
articles = Article.objects.select_related("author", "category").all()
for article in articles:
    print(article.author.name)  # No extra query -- already loaded

# Chain through relationships
comments = (
    Comment.objects
    .select_related("article__author", "article__category")
    .filter(is_approved=True)
)

Read the full file on GitHub · 269 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 First seen · 269 lines · 71 tokens per session scan A 4e51fad450da

Subscribe to this mod's changes

django-orm-mastery is a skill published in the GitHub repository VersoXBT/claude-initial-setup (4 stars, last pushed 5mo ago), licensed MIT. It adds 71 tokens to every session and 1,907 once invoked, about $0.0003 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-09-03.