Command reference¶
Every flag admin_generator accepts, grouped by the job it does. The
authoritative list is always ./manage.py admin_generator --help, which is
generated from the same parser.
Arguments¶
- app¶
The app to generate admin definitions for. Accepts the short label (
blog) or the full dotted path (myproject.blog). The literal valueallgenerates for every local app, meaning every app outsidesite-packagesand outside a virtualenv in the project directory.
- models¶
Zero or more regular expressions, matched case-insensitively against model names. Only matching models are generated. Omit them for the whole app.
Output¶
- -w, --write¶
Write to the app’s
admin.pyinstead of stdout. Without it the generated source goes to stdout and nothing on disk changes.
- -o OUTPUT, --output OUTPUT¶
Output file name,
admin.pyby default. A bare name is resolved relative to the app’s directory. A name containing a path separator is used as given.
- -f, --force¶
Overwrite the output file if it already exists. Without
-for-aan existing file aborts the run.
- -a, --append¶
Append to the output file instead of replacing it. Useful for collecting several filtered runs into one file.
Heuristics¶
These flags move the thresholds described in What the generator decides.
- -l THRESHOLD, --list-filter-threshold THRESHOLD¶
A foreign key or field with fewer than this many distinct values becomes a
list_filterentry. Defaults to 25.
- -r THRESHOLD, --raw-id-threshold THRESHOLD¶
A foreign key with more than this many rows becomes a
raw_id_fieldsentry rather than a select box. Defaults to 100.
- --date-hierarchy-threshold THRESHOLD¶
A model with fewer than this many rows may get a
date_hierarchy. Defaults to 250.
- -s NAME, --search-field NAME¶
Add a field name that should end up in
search_fields. Repeatable, and added to the defaultsnameandslug.
- -d NAME, --date-hierarchy NAME¶
Add a field name that may be used as
date_hierarchy. Repeatable, and added to the defaultsjoined_at,updated_atandcreated_at.
- -p SPEC, --prepopulated-fields SPEC¶
Add a
field=other_fieldpair forprepopulated_fields. Repeatable, and added to the defaultslug=name.
- -n, --no-query-db¶
Never query the database. Row counts are what decide between a dropdown filter and a raw id field, so this trades accuracy for speed and for the ability to run against an empty or unavailable database.
Integrations¶
- --disable-json-widget¶
Leave out the
django-json-widgetimport and theJSONFieldformfield_overrides.
- --disable-auto-complete¶
Never emit
autocomplete_fieldsfor many-to-many relations.
- --auto-complete FIELD¶
Emit
autocomplete_fieldsonly for the named field. Repeatable.
- --enable-reversion¶
Generate
django-reversionsupport, giving matching models aVersionAdminbase class.
- --reversion-admin-regex REGEX¶
Restrict reversion support to models matching this expression. Defaults to
.*.
- --reversion-admin-class CLASS¶
Base class used for reversion-enabled models. Defaults to
VersionAdmin.
- --reversion-admin-class-import IMPORT¶
The import statement emitted for that base class. Defaults to
from reversion.admin import VersionAdmin.
- --admin-class CLASS¶
Base class for the generated
ModelAdminclasses. Defaults toadmin.ModelAdmin.
- --admin-class-import IMPORT¶
The import statement emitted for a non-default
--admin-class. Empty by default, because the Django base class is already imported.
Recipes¶
Print one model’s admin without touching the database:
./manage.py admin_generator blog '^post$' --no-query-db
Regenerate the whole project with a stricter raw id threshold:
./manage.py admin_generator all --write --force --raw-id-threshold 25
Collect two apps into one reviewed file:
./manage.py admin_generator blog -o /tmp/admin.py -f
./manage.py admin_generator shop -o /tmp/admin.py -a
Build on a project-wide base class:
./manage.py admin_generator blog \
--admin-class BaseAdmin \
--admin-class-import 'from myproject.admin import BaseAdmin'