django-idioms
Skill157 starsChanged 4 months agoMITView on GitHub
Django and Django REST Framework (DRF) patterns: ORM queries, model managers, class-based views, serializers, migrations, and pytest-django testing. Use when building or maintaining Django backend applications. Pair with python-idioms.
In this repository59 other files it gives its agents.
- github-pages/agents.mdAGENTS.md
- adrSkill
- agent-protocolsSkill
- angular-idiomsSkill
- api-documentationSkill
- axum-idiomsSkill
- browser-automationSkill
- chaos-testingSkill
- ci-cdSkill
- cli-developmentSkill
- code-auditSkill
- code-reviewSkill
- cpp-idiomsSkill
- csharp-idiomsSkill
- data-engineeringSkill
- debugging-protocolSkill
- dotnet-idiomsSkill
- elixir-idiomsSkill
- embedded-systemsSkill
- feature-flagsSkill
- flutter-idiomsSkill
- frontend-designSkill
- git-commit-integritySkill
- go-idiomsSkill
- guardrailsSkill
- hono-idiomsSkill
- incident-responseSkill
- java-idiomsSkill
- javascript-idiomsSkill
- kotlin-idiomsSkill
- laravel-idiomsSkill
- logging-implementationSkill
- ml-engineeringSkill
- mobile-designSkill
- mobile-testingSkill
- nextjs-idiomsSkill
- parallel-dispatchSkill
- payment-integrationSkill
- perf-optimizationSkill
- php-idiomsSkill
- postgres-idiomsSkill
- python-idiomsSkill
- rails-idiomsSkill
- react-idiomsSkill
- refactoring-patternsSkill
- research-methodologySkill
- ruby-idiomsSkill
- rust-idiomsSkill
- security-auditSkill
- sequential-thinkingSkill
- spring-boot-idiomsSkill
- sql-idiomsSkill
- structured-specSkill
- supply-chain-securitySkill
- swift-idiomsSkill
- testability-patternsSkill
- testing-strategySkill
- typescript-idiomsSkill
- vue-idiomsSkill
The file
Files
Django Idioms and Patterns
Django rewards convention, the ORM, and "batteries included" design. Idiomatic Django = DRY, model-centric, well-tested.
Scope: Django-specific patterns. For Python:
@.agents/skills/python-idioms/SKILL.md.
Models
- Fat models, thin views — business logic in models/managers, not views.
- Custom managers for common queries:
class TaskManager(models.Manager): def active(self): return self.filter(status='active') class Task(models.Model): objects = TaskManager() Metaclass for ordering, constraints, indexes.
Views
- Class-based views for CRUD, function-based for simple/custom:
class TaskListView(LoginRequiredMixin, ListView): model = Task queryset = Task.objects.active() paginate_by = 25 - DRF serializers for API boundaries:
class TaskSerializer(serializers.ModelSerializer): class Meta: model = Task fields = ['id', 'title', 'priority', 'created_at'] read_only_fields = ['id', 'created_at']
ORM
select_related/prefetch_relatedto avoid N+1 queries.F()andQ()expressions for complex queries.- Never raw SQL unless ORM can't express it (and then use parameterized queries).
Migrations
- One migration per logical change. Squash when history grows.
- Data migrations in separate migration files from schema changes.
RunPythonwithreverse_codefor reversibility.
Testing
For universal testing principles, see
.agents/rules/testing-strategy.md. Below: language-specific patterns only.
pytest-djangooverunittest.TestCase:@pytest.mark.django_db def test_create_task(): task = Task.objects.create(title='Test', priority='high') assert task.title == 'Test'- Factory Boy for test data (not fixtures).
Formatting and Static Analysis
| Tool | Purpose | Command |
ruff | Formatting + linting | ruff format . && ruff check . |
mypy + django-stubs | Type checking | mypy . |
bandit | Security | bandit -r . |
Related
- Code Idioms and Conventions @.agents/rules/code-idioms-and-conventions.md
- Python Idioms @.agents/skills/python-idioms/SKILL.md
- Security Principles @.agents/rules/security-principles.md
- Architectural Patterns @.agents/rules/architectural-pattern.md
- Database Design Principles @.agents/rules/database-design-principles.md
- Error Handling Principles @.agents/rules/error-handling-principles.md
- Testing Strategy @.agents/rules/testing-strategy.md
- Logging and Observability Mandate @.agents/rules/logging-and-observability-mandate.md
- Logging and Observability Principles @.agents/skills/logging-implementation/SKILL.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

