All skills
jeffallan avatar

/django-expert

@2bb8261
by jeffallanjeffallan/claude-skills12k stars
1,124

Use when building Django web applications or REST APIs with Django REST Framework. Invoke when working with settings.py, models.py, manage.py, or any Django project file. Creates Django models with proper indexes, optimizes ORM queries using select_related/prefetch_related, builds DRF serializers and viewsets, and configures JWT authentication. Trigger terms: Django, DRF, Django REST Framework, Django ORM, Django model, serializer, viewset, Python web.

Use this Skill: https://skilld.dev/gh/jeffallan/claude-skills/django-expert

This session only. Nothing lands on disk.

referencesauthentication.md

≈991 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Authentication

SimpleJWT Setup

# settings.py
INSTALLED_APPS = [
    ...
    'rest_framework_simplejwt',
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
}

from datetime import timedelta

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=15),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
    'ROTATE_REFRESH_TOKENS': True,
    'BLACKLIST_AFTER_ROTATION': True,
    'AUTH_HEADER_TYPES': ('Bearer',),
}

# urls.py
from rest_framework_simplejwt.views import (
    TokenObtainPairView,
    TokenRefreshView,
)

urlpatterns = [
    path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
    path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]

Custom Token Claims

from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView

class CustomTokenObtainPairSerializer(TokenObtainPairSerializer):
    @classmethod
    def get_token(cls, user):
        token = super().get_token(user)
        # Add custom claims
        token['email'] = user.email
        token['role'] = user.role
        return token

class CustomTokenObtainPairView(TokenObtainPairView):
    serializer_class = CustomTokenObtainPairSerializer

Custom Permissions

from rest_framework import permissions

class IsOwnerOrReadOnly(permissions.BasePermission):
    def has_object_permission(self, request, view, obj):
        if request.method in permissions.SAFE_METHODS:
            return True
        return obj.created_by == request.user

class IsAdminOrReadOnly(permissions.BasePermission):
    def has_permission(self, request, view):
        if request.method in permissions.SAFE_METHODS:
            return True
        return request.user.is_staff

class HasAPIKey(permissions.BasePermission):
    def has_permission(self, request, view):
        api_key = request.headers.get('X-API-Key')
        return api_key == settings.API_KEY

Permission Classes on ViewSet

class ProductViewSet(viewsets.ModelViewSet):
    permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]

    def get_permissions(self):
        if self.action == 'destroy':
            return [permissions.IsAdminUser()]
        if self.action in ['create', 'update', 'partial_update']:
            return [permissions.IsAuthenticated()]
        return [permissions.AllowAny()]

User Registration

class RegisterSerializer(serializers.ModelSerializer):
    password = serializers.CharField(write_only=True, min_length=8)
    password_confirm = serializers.CharField(write_only=True)

    class Meta:
        model = User
        fields = ['email', 'username', 'password', 'password_confirm']

    def validate(self, attrs):
        if attrs['password'] != attrs['password_confirm']:
            raise serializers.ValidationError("Passwords don't match")
        return attrs

    def create(self, validated_data):
        validated_data.pop('password_confirm')
        return User.objects.create_user(**validated_data)

class RegisterView(generics.CreateAPIView):
    serializer_class = RegisterSerializer
    permission_classes = [permissions.AllowAny]

Current User Endpoint

class CurrentUserView(generics.RetrieveUpdateAPIView):
    serializer_class = UserSerializer
    permission_classes = [permissions.IsAuthenticated]

    def get_object(self):
        return self.request.user

Quick Reference

Permission Access
AllowAny Everyone
IsAuthenticated Logged in users
IsAdminUser Staff users
IsAuthenticatedOrReadOnly Auth for write
JWT Endpoint Purpose
/token/ Get access + refresh
/token/refresh/ New access from refresh
/token/verify/ Validate token

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk CRITICAL
  • Gen Agent Trust Hub16d

    A comprehensive Django and Django REST Framework development assistant. The skill promotes security best practices such as avoiding raw SQL, using environment variables for secrets, and implementing proper permissions. It has a low risk of indirect prompt injection because it is designed to analyze and process user-provided code files.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    6 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 2bb8261. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 2 months ago
Other metadata
metadata
{
  "author": "https://github.com/Jeffallan",
  "version": "1.1.0",
  "domain": "backend",
  "triggers": "Django, DRF, Django REST Framework, Django ORM, Django model, serializer, viewset, Python web",
  "role": "specialist",
  "scope": "implementation",
  "output-format": "code",
  "related-skills": "fullstack-guardian, fastapi-expert, test-master, django-storages-s3"
}

README badge

README badge for jeffallan/claude-skills/django-expert

Builds Django REST Framework APIs and models with proper indexing, query optimization via select_related/prefetch_related, DRF serializers with validation, viewsets with permissions, and JWT authentication. Targets Django 5.0 projects and provides workflows for schema design, ORM optimization, and APITestCase testing.

Generated from the current SKILL.md.

Does this skill work with Django 4.x or only Django 5.0?
The skill is built around Django 5.0 and its async views. It may work with Django 4.x but is optimized for Django 5.0 features.
Does this cover Django REST Framework setup and serializers?
Yes. The skill includes DRF serializer design with validation, viewset implementation, and API endpoint configuration with proper permissions.
Does this skill handle authentication?
Yes. It covers JWT authentication via SimpleJWT, session authentication, and permission classes like IsAuthenticatedOrReadOnly.
Will this optimize my existing Django queries?
Yes. The skill emphasizes select_related and prefetch_related to prevent N+1 queries, and recommends database indexes on frequently queried fields.
Does this include testing guidance?
Yes. The skill covers APITestCase, fixtures, and factories for testing Django models and API endpoints, with a reference guide for pytest-django.

Generated from the current SKILL.md. These answers refresh after source changes.