django-completion: project-aware tab completion for manage.py (app labels, migration names, bash/zsh)

The problem

Django ships a bash completion script in extras/django_bash_completion, but
it requires manual setup and only covers command names and flags. This has been
an open issue since ticket #1240 way back in 2006 β€” the hard part being app-label and
migration-name completion, which requires project context.

To complete migrate accounts 0002<TAB>, the shell needs to know what
migrations exist in the accounts app β€” which means loading
DJANGO_SETTINGS_MODULE and calling django.setup(), initializing the full
app registry on every keystroke. That’s too expensive to do at completion time.


The approach: a post-command cache

After each manage.py invocation, a signal fires discovery (commands, apps,
migrations, options) and writes a small JSON cache into the project root. The
shell completion script reads that file β€” no Django import, no subprocess, no
database round-trip.

The cache refreshes automatically on every manage.py run, so it stays in
sync without any extra steps.


What it completes

  • Management command names
  • App labels (filtered: only apps with migrations for the migrate command)
  • Migration names after migrate <app>
  • Option flags for any command

Supported invocation styles: python manage.py, python3 manage.py,
./manage.py, uv run python manage.py

demo


Install

pip install django-completion

Add django_completion to INSTALLED_APPS, then:

python manage.py autocomplete install

Restart terminal. Tab works.


GitHub: GitHub - soldatov-ss/django-completion: Tab completion for Django's manage.py β€” commands, app labels, options, and migration targets in bash and zsh Β· GitHub

Oh, this looks really cool. Thank you for sharing!