{"data":{"slug":"discovered-ba063bc8d8205e87c217662bee7b466b8620264838307649","title":"Django Expert","summary":"Builds Django web applications or REST APIs with Django REST Framework. Creates Django models with proper indexes, optimizes ORM queries using select_related\/prefetch_related, builds DRF serializers and viewsets, and configures JWT authentication.","url":"https:\/\/skillshunter.net\/skills\/discovered-ba063bc8d8205e87c217662bee7b466b8620264838307649","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-ba063bc8d8205e87c217662bee7b466b8620264838307649","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-ba063bc8d8205e87c217662bee7b466b8620264838307649.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-ba063bc8d8205e87c217662bee7b466b8620264838307649\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure environment variables are used for secrets and avoid storing them in settings.py. Run `manage.py makemigrations` and `manage.py migrate` after designing models to verify the schema.","instructions":"---\nname: django-expert\ndescription: \"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.\"\nlicense: MIT\nmetadata:\n  author: https:\/\/github.com\/Jeffallan\n  company: https:\/\/synergetic.solutions\n  version: \"1.1.0\"\n  domain: backend\n  triggers: Django, DRF, Django REST Framework, Django ORM, Django model, serializer, viewset, Python web\n  role: specialist\n  scope: implementation\n  output-format: code\n  related-skills: fullstack-guardian, fastapi-expert, test-master, django-storages-s3, flask-expert\n---\n\n# Django Expert\n\nSenior Django specialist with deep expertise in Django 5.0, Django REST Framework, and production-grade web applications.\n\n## When to Use This Skill\n\n- Building Django web applications or REST APIs\n- Designing Django models with proper relationships\n- Implementing DRF serializers and viewsets\n- Optimizing Django ORM queries\n- Setting up authentication (JWT, session)\n- Django admin customization\n\n## Core Workflow\n\n1. **Analyze requirements** \u2014 Identify models, relationships, API endpoints\n2. **Design models** \u2014 Create models with proper fields, indexes, managers \u2192 run `manage.py makemigrations` and `manage.py migrate`; verify schema before proceeding\n3. **Implement views** \u2014 DRF viewsets or Django 5.0 async views\n4. **Validate endpoints** \u2014 Confirm each endpoint returns expected status codes with a quick `APITestCase` or `curl` check before adding auth\n5. **Add auth** \u2014 Permissions, JWT authentication\n6. **Test** \u2014 Django TestCase, APITestCase\n\n## Reference Guide\n\nLoad detailed guidance based on context:\n\n| Topic | Reference | Load When |\n|-------|-----------|-----------|\n| Models | `references\/models-orm.md` | Creating models, ORM queries, optimization |\n| Serializers | `references\/drf-serializers.md` | DRF serializers, validation |\n| ViewSets | `references\/viewsets-views.md` | Views, viewsets, async views |\n| Authentication | `references\/authentication.md` | JWT, permissions, SimpleJWT |\n| Testing | `references\/testing-django.md` | APITestCase, fixtures, factories |\n\n## Minimal Working Example\n\nThe snippet below demonstrates the core MUST DO constraints: indexed fields, `select_related`, serializer validation, and endpoint permissions.\n\n```python\n# models.py\nfrom django.db import models\n\nclass Article(models.Model):\n    title = models.CharField(max_length=255, db_index=True)\n    author = models.ForeignKey(\n        \"auth.User\", on_delete=models.CASCADE, related_name=\"articles\"\n    )\n    published_at = models.DateTimeField(auto_now_add=True, db_index=True)\n\n    class Meta:\n        ordering = [\"-published_at\"]\n        indexes = [models.Index(fields=[\"author\", \"published_at\"])]\n\n    def __str__(self):\n        return self.title\n\n# serializers.py\nfrom rest_framework import serializers\nfrom .models import Article\n\nclass ArticleSerializer(serializers.ModelSerializer):\n    author_username = serializers.CharField(source=\"author.username\", read_only=True)\n\n    class Meta:\n        model = Article\n        fields = [\"id\", \"title\", \"author_username\", \"published_at\"]\n\n    def validate_title(self, value):\n        if len(value.strip()) < 3:\n            raise serializers.ValidationError(\"Title must be at least 3 characters.\")\n        return value.strip()\n\n# views.py\nfrom rest_framework import viewsets, permissions\nfrom .models import Article\nfrom .serializers import ArticleSerializer\n\nclass ArticleViewSet(viewsets.ModelViewSet):\n    \"\"\"\n    Uses select_related to avoid N+1 on author lookups.\n    IsAuthenticatedOrReadOnly: safe methods are public, writes require auth.\n    \"\"\"\n    serializer_class = ArticleSerializer\n    permission_classes = [permissions.IsAuthenticatedOrReadOnly]\n\n    def get_queryset(self):\n        return Article.objects.select_related(\"author\").all()\n\n    def perform_create(self, serializer):\n        serializer.save(author=self.request.user)\n```\n\n```python\n# tests.py\nfrom rest_framework.test import APITestCase\nfrom rest_framework import status\nfrom django.contrib.auth.models import User\n\nclass ArticleAPITest(APITestCase):\n    def setUp(self):\n        self.user = User.objects.create_user(\"alice\", password=\"<test-password>\")\n\n    def test_list_public(self):\n        res = self.client.get(\"\/api\/articles\/\")\n        self.assertEqual(res.status_code, status.HTTP_200_OK)\n\n    def test_create_requires_auth(self):\n        res = self.client.post(\"\/api\/articles\/\", {\"title\": \"Test\"})\n        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)\n\n    def test_create_authenticated(self):\n        self.client.force_authenticate(self.user)\n        res = self.client.post(\"\/api\/articles\/\", {\"title\": \"Hello Django\"})\n        self.assertEqual(res.status_code, status.HTTP_201_CREATED)\n```\n\n## Constraints\n\n### MUST DO\n- Use `select_related`\/`prefetch_related` for related objects\n- Add database indexes for frequently queried fields\n- Use environment variables for secrets\n- Implement proper permissions on all endpoints\n- Write tests for models and API endpoints\n- Use Django's built-in security features (CSRF, etc.)\n\n### MUST NOT DO\n- Use raw SQL without parameterization\n- Skip database migrations\n- Store secrets in settings.py\n- Use DEBUG=True in production\n- Trust user input without validation\n- Ignore query optimization\n\n## Output Templates\n\nWhen implementing Django features, provide:\n1. Model definitions with indexes\n2. Serializers with validation\n3. ViewSet or views with permissions\n4. Brief note on query optimization\n\n## Knowledge Reference\n\nDjango 5.0, DRF, async views, ORM, QuerySet, select_related, prefetch_related, SimpleJWT, django-filter, drf-spectacular, pytest-django\n\nMaintained by [@jeffallan](https:\/\/github.com\/jeffallan), Principal Consultant at [Synergetic Solutions](https:\/\/synergetic.solutions)\n\n[Documentation](https:\/\/jeffallan.github.io\/claude-skills\/skills\/backend\/django-expert\/)\n","use_cases":["Designing Django models with proper relationships and indexes","Implementing DRF serializers and viewsets","Optimizing Django ORM queries with select_related and prefetch_related","Setting up authentication (JWT, session) and permissions","Writing tests for models and API endpoints"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/Jeffallan\/claude-skills\/blob\/a8be463010e2ca23afe00ea00773aea7128e8971\/plugin\/skills\/django-expert\/SKILL.md","source_commit":"a8be463010e2ca23afe00ea00773aea7128e8971","license":null,"version":null,"listing_approved_at":"2026-11-29","created_at":"2026-11-28T18:46:54.000000Z","updated_at":"2026-11-29T10:53:15.000000Z","seo_title":"Django Expert - Build REST APIs and Django Web Applications","seo_description":"A Django expert skill for creating optimized Django models, REST APIs with DRF, and implementing security features like JWT authentication and proper permissions.","seo_keywords":["Django","DRF","Django REST Framework","Django ORM","Django model","serializer","viewset","Python web"]}}