Back to Skills

django-orm-patterns

verified

Use when Django ORM patterns with models, queries, and relationships. Use when building database-driven Django applications.

View on GitHub

Marketplace

han

TheBushidoCollective/han

Plugin

jutsu-django

Technique

Repository

TheBushidoCollective/han
60stars

jutsu/jutsu-django/skills/django-orm-patterns/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-django/skills/django-orm-patterns/SKILL.md -a claude-code --skill django-orm-patterns

Installation paths:

Claude
.claude/skills/django-orm-patterns/
Powered by add-skill CLI

Instructions

# Django ORM Patterns

Master Django ORM for building efficient, scalable database-driven
applications with complex queries and relationships.

## Model Definition

Define models with proper field types, constraints, and metadata.

```python
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator

class User(models.Model):
    email = models.EmailField(unique=True, db_index=True)
    name = models.CharField(max_length=100)
    is_active = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-created_at']
        indexes = [
            models.Index(fields=['email']),
            models.Index(fields=['created_at', 'is_active']),
        ]
        verbose_name = 'User'
        verbose_name_plural = 'Users'

    def __str__(self):
        return self.email

class Post(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
    published = models.BooleanField(default=False)
    views = models.PositiveIntegerField(default=0)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['-created_at']
        indexes = [
            models.Index(fields=['author', 'published']),
        ]
```

## QuerySet API Basics

Use Django's QuerySet API for efficient database queries.

```python
# All records
users = User.objects.all()

# Filtering
active_users = User.objects.filter(is_active=True)
inactive_users = User.objects.exclude(is_active=True)

# Get single record (raises exception if not found or multiple found)
user = User.objects.get(email='user@example.com')

# Get or create
user, created = User.objects.get_or_create(
    email='user@example.com',
    defaults={'name': 'John Doe'}
)

# Update or create
user, created = User.objects.update_or_create(
 

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
32179 chars