Django admin scaffolding

Stop hand-writing admin.py

A management command that reads your models and prints a complete admin.py: list displays, filters, search fields, raw id fields, date hierarchies, prepopulated slugs and autocompletes. You review the output and keep what you want.

Generate an admin in one command

Install the package on Python 3.10 or later and add it to INSTALLED_APPS:

python -m pip install django-admin-generator

Point the command at an app and read the result:

./manage.py admin_generator blog
class PostAdmin(ModelAdminBase):
    list_display = ('id', 'title', 'author', 'category', 'is_published')
    list_filter = ('created_at', 'published_at', 'is_published', 'author')
    autocomplete_fields = ('tags',)
    search_fields = ('slug',)
    prepopulated_fields = {'slug': ['title']}
    date_hierarchy = 'created_at'

Nothing is written to disk until you ask for it, so the first run is always safe. Add --write once the output looks right.

A generated changelist with columns, a filter sidebar and a date drill-down

The changelist above, filter sidebar and date drill-down included, came from that single command with no hand-written admin code.

Pick your next step

Note

The generator inspects your models and, unless you pass --no-query-db, counts rows to decide between a dropdown filter and a raw id field. Point it at a database that resembles production if you want those counts to be meaningful.