home / skills / dexploarer / claudius-skills / django-model-helper
This skill generates Django models with proper fields, relationships, and migrations, speeding up schema design and ensuring best practices.
npx playbooks add skill dexploarer/claudius-skills --skill django-model-helperReview the files below or copy the command above to add this skill to your agents.
---
name: django-model-helper
description: Generates Django models with proper field types, relationships, and migrations. Use when creating Django models or database schemas.
allowed-tools: [Write, Read, Bash]
---
# Django Model Helper
Generates Django models following best practices.
## When to Use
- "Create a Django model for users"
- "Generate Product model"
- "Add BlogPost model with relationships"
## Model Generation
```python
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
"""Custom user model."""
bio = models.TextField(blank=True)
avatar = models.ImageField(upload_to='avatars/', blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'users'
ordering = ['-created_at']
def __str__(self):
return self.username
class Post(models.Model):
"""Blog post model."""
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='posts')
content = models.TextField()
published_at = models.DateTimeField(null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
db_table = 'posts'
ordering = ['-published_at']
indexes = [
models.Index(fields=['slug']),
models.Index(fields=['author', '-published_at']),
]
def __str__(self):
return self.title
```
## After Creating Model
1. Generate migration:
```bash
python manage.py makemigrations
```
2. Apply migration:
```bash
python manage.py migrate
```
## Best Practices
- Use appropriate field types
- Add indexes for frequently queried fields
- Define __str__ methods
- Use Meta class for table name and ordering
- Add related_name to relationships
- Include created_at/updated_at timestamps
- Use on_delete properly
- Add helpful docstrings
This skill generates Django models, complete with appropriate field types, relationships, Meta options, and migration guidance. It helps translate data requirements into Django ORM classes that follow common conventions and best practices. Use it to speed up schema design and produce ready-to-migrate model code.
Provide entity descriptions, field lists, and relationship requirements; the skill outputs Django model classes with proper fields, related_name, on_delete behavior, indexes, and __str__ methods. It also suggests Meta settings (db_table, ordering) and explicit timestamps, and provides the exact manage.py commands to create and apply migrations. The output is concise, copy-paste ready Python code that integrates with typical Django projects.
Will the skill create migrations automatically?
No. It generates model code and shows the exact commands (python manage.py makemigrations and migrate) you should run to create and apply migrations.
Can it handle custom user models?
Yes. It can generate custom user models that extend AbstractUser or AbstractBaseUser and include additional fields and Meta configuration.