BACK TO TEMPLATES
rulesany

Django Enterprise App Rules

Enterprise AGENTS.md for Django applications specifying ORM optimizations, migrations, and pytest-django rules.

When to use this

Place this file in Django codebases to prevent common ORM N+1 query performance traps, migration issues, and untyped views.

The template

# AGENTS.md

## Project Context

Django web backend with Django REST Framework (DRF), PostgreSQL database, and Celery background workers.

## Commands

- `python manage.py runserver` start Django development server
- `pytest` run full test suite with pytest-django
- `python manage.py makemigrations` create database migration scripts
- `python manage.py check` perform Django self-diagnostics

Always run `pytest` and verify migrations run cleanly before completing work.

## Conventions

- Prevent N+1 queries by using `select_related()` and `prefetch_related()` on QuerySets.
- Class-based views and serializers must specify explicit field listings (`fields = [...]`).
- Business logic lives in service layer modules under `services/`, not inside models or views.

## Restrictions

- Do not use `fields = '__all__'` in serializers or model forms.
- Do not execute long-running blocking tasks within HTTP request handlers; use Celery tasks.

## Approval Required

- Adding new model fields or database migrations.
- Modifying Django settings or middleware configuration.

Customization Guide

Customize settings module names and test commands according to your project environment.

Last verified 2026-07-26