.cursor/skills/django-models/SKILL.md
Django model design patterns emphasizing fat models/thin views, QuerySet optimization, and domain logic encapsulation. Use when designing models, optimizing queries, implementing business logic, or working with the ORM.
npx skillsauth add AngelDann/app-comisions-dist django-modelsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Business logic belongs in models and managers, not views. Views orchestrate workflows; models implement domain behavior. This principle creates testable, reusable code that stays maintainable as complexity grows.
Good: Model methods handle business rules, state transitions, validation Bad: Views contain if/else logic for domain rules, calculate derived values
TextChoices/IntegerChoices for status fields and enumsget_absolute_url() for canonical object URLs__str__() for readable representationsordering in Meta for consistent default sortingblank=True, default="" for optional text fields (avoid null)null=True, blank=True for optional foreign keysnull=True to avoid collision issuesJSONField for flexible metadata (avoid creating many optional fields)max_length based on actual data needspost.publish(), order.cancel()post.is_editable_by(user)invoice.calculate_total()update_fields when saving partial changesCustom QuerySet classes are your secret weapon. They make queries reusable, chainable, and testable.
Define a QuerySet subclass with domain-specific filter methods
Attach it to your model: objects = YourQuerySet.as_manager()
Chain methods for composable queries
.exists() instead of if queryset: or if len(queryset):.count() instead of len(queryset.all())annotate(): Add computed fields to each object (Count, Sum, Avg, etc.)aggregate(): Compute values across entire querysetF() expressions for database-level updates (views=F('views') + 1)Use QuerySets for chainable query logic. Use Managers for model-level operations that don't return querysets.
Manager: Think "factory methods" - User.objects.create_user()
QuerySet: Think "filters and transformations" - Post.objects.published().recent()
Most of the time, you want a custom QuerySet, not a custom Manager.
Signals create implicit coupling and make code harder to follow. Prefer explicit method calls.
Rule of thumb: If you control both the trigger and the reaction, don't use a signal.
makemigrations after model changesmigrate to apply migrationsCreate with makemigrations --empty app_name. Use apps.get_model() to access models (not direct imports). Write both forward and reverse operations.
Use data migrations for: Populating new fields, transforming data, migrating between fields.
select_related()/prefetch_related()if queryset: instead of .exists()len() to count instead of .count()Works with:
Adapted from claude-code-django (.claude/skills/django-models).
development
pytest-django testing patterns, Factory Boy, fixtures, and TDD workflow. Use when writing tests, creating test factories, or following TDD red-green-refactor cycle.
development
HTMX patterns for Django including partial templates, hx-* attributes, and dynamic UI without JavaScript. Use when building interactive UI, handling AJAX requests, or creating dynamic components.
development
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
development
Check if documentation is in sync with code. Use when the user wants to verify that documentation matches current code, find outdated docs, or audit documentation accuracy. Triggers on requests like "check docs", "sync documentation", "are the docs up to date", "/docs-sync".