django

Fix Django ORM and DRF serialization mistakes in production code.

13|Updated Mar 15, 2019
One-click install
npx skills add https://github.com/WTFox/dotfiles --skill django-wtfox
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django
Source: https://github.com/WTFox/dotfiles/tree/main/claude/.claude/skills/django
Command: npx skills add https://github.com/WTFox/dotfiles --skill django-wtfox

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Load when writing, reviewing, or debugging Django code — models, views, DRF serializers, viewsets, URL routing, signals, or admin. Covers the patterns Claude consistently gets wrong: queryset filtering, N+1 via ORM relationships, DRF serializer validation, permission classes, and queryset ownership scoping.

Core Features & Use Cases

  • Ownership scoping in get_queryset to prevent data leakage.
  • Eliminate N+1 queries with select_related and prefetch_related strategies.
  • Enforce explicit serializer fields and proper perform_create usage to set request-derived data.
  • Implement reusable object-level permissions to centralize access control.
  • Design models with on_delete behavior, indexing, and clear str representations for maintainability.

Quick Start

Review a Django 4.x project and apply the ownership in get_queryset, the select_related/prefetch_related optimizations, and explicit serializer fields.

Frequently Asked Questions about django

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Django ORM N+1 query problems with select_related and prefetch_related?

Fix Django ORM N+1 queries by applying select_related for foreign-key joins and prefetch_related for reverse relationships. This strategy eliminates redundant database hits when accessing related model data in viewsets and serializers.

What's the best way to scope ownership in DRF get_queryset to prevent data leakage?

Scope ownership in DRF get_queryset by filtering querysets against the requesting user. This ownership scoping pattern centralizes data access control in viewsets, preventing users from accessing unauthorized records.

How do I properly use DRF perform_create and explicit serializer fields?

Use DRF perform_create to set request-derived data and define explicit serializer fields instead of relying on implicit inclusion. This pattern enforces validation and prevents accidental data exposure during object creation.

How do I implement reusable object-level permissions in Django REST Framework?

Implement reusable object-level permissions by creating custom permission classes that centralize access control logic. This approach enforces consistent security policies across Django REST Framework viewsets.

What Django model design best practices improve maintainability for production?

Django model design best practices include defining explicit on_delete behavior, adding database indexing, and writing clear __str__ representations. These patterns ensure production-grade maintainability and predictable query performance.