Metadata-Version: 2.4
Name: django-admin-generator
Version: 3.1.0
Summary: Django Admin Generator is a management command to automatically generate a Django `admin.py` file for given apps/models.
Keywords: django,admin,generator,scaffold
Author: Rick van Hattem
Author-email: Rick van Hattem <Wolph@Wol.ph>
License-Expression: BSD-3-Clause
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Dist: django-utils2>=4.1.2
Requires-Dist: python-utils>=4.0.1
Requires-Dist: django>=4.2 ; extra == 'demo'
Requires-Dist: django-admin-generator[tests] ; extra == 'dev'
Requires-Dist: ruff>=0.15.0 ; extra == 'dev'
Requires-Dist: mypy>=1.10 ; extra == 'dev'
Requires-Dist: django-stubs[compatible-mypy]>=5.0 ; extra == 'dev'
Requires-Dist: pyright>=1.1 ; extra == 'dev'
Requires-Dist: pyrefly>=0.1 ; extra == 'dev'
Requires-Dist: sphinx>=7 ; extra == 'docs'
Requires-Dist: furo>=2024.1.29 ; extra == 'docs'
Requires-Dist: django>=4.2 ; extra == 'docs'
Requires-Dist: pytest>=8 ; extra == 'tests'
Requires-Dist: pytest-cov>=5 ; extra == 'tests'
Requires-Dist: pytest-django>=4.8 ; extra == 'tests'
Requires-Dist: coverage>=7 ; extra == 'tests'
Requires-Dist: django>=4.2 ; extra == 'tests'
Requires-Dist: tox>=4.0 ; extra == 'tox'
Requires-Dist: tox-uv>=1.0 ; extra == 'tox'
Requires-Dist: tox-gh-actions>=3.0 ; extra == 'tox'
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/WoLpH/django-admin-generator/
Project-URL: Documentation, https://django-admin-generator.readthedocs.io/
Project-URL: Source, https://github.com/WoLpH/django-admin-generator/
Project-URL: Bug Reports, https://github.com/WoLpH/django-admin-generator/issues
Project-URL: Funding, https://github.com/sponsors/wolph
Provides-Extra: demo
Provides-Extra: dev
Provides-Extra: docs
Provides-Extra: tests
Provides-Extra: tox
Description-Content-Type: text/markdown

<h1 align="center">Django Admin Generator</h1>

<p align="center"><strong>Scaffold a complete, sensible Django admin for your models in one command.</strong></p>

[![CI on master](https://img.shields.io/github/actions/workflow/status/wolph/django-admin-generator/ci.yml?branch=master&label=CI&style=flat-square&labelColor=555)](https://github.com/wolph/django-admin-generator/actions/workflows/ci.yml?query=branch%3Amaster)
[![Coverage on master](https://img.shields.io/coverallsCoverage/github/wolph/django-admin-generator?branch=master&style=flat-square&labelColor=555)](https://coveralls.io/github/wolph/django-admin-generator?branch=master)
[![PyPI version](https://img.shields.io/pypi/v/django-admin-generator.svg?style=flat-square&labelColor=555&color=007ec6)](https://pypi.org/project/django-admin-generator/)
[![Python versions](https://img.shields.io/pypi/pyversions/django-admin-generator.svg?style=flat-square&labelColor=555&color=007ec6)](https://pypi.org/project/django-admin-generator/)
[![Monthly downloads](https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Fapi.pepy.tech%2Fbadge%2Fdjango-admin-generator%2Fmonth&query=%28%2F%2F%2A%5Blocal-name%28%29%3D%22text%22%5D%29%5Blast%28%29%5D&label=downloads%2Fmonth&style=flat-square&labelColor=555&color=007ec6)](https://pepy.tech/projects/django-admin-generator)
[![Documentation](https://img.shields.io/readthedocs/django-admin-generator/latest?style=flat-square&labelColor=555)](https://django-admin-generator.readthedocs.io/en/latest/)
[![License](https://img.shields.io/pypi/l/django-admin-generator.svg?style=flat-square&labelColor=555&color=007ec6)](https://github.com/WoLpH/django-admin-generator/blob/develop/LICENSE)

`django-admin-generator` is a management command that introspects your models
and writes a ready-to-use `admin.py`: `list_display`, `list_filter`,
`search_fields`, `raw_id_fields`, `date_hierarchy`, `prepopulated_fields` and
autocomplete, so you don't have to hand-write any of it.

![Auto-generated changelist](https://raw.githubusercontent.com/WoLpH/django-admin-generator/develop/docs/images/changelist.png)

*The list view above, filter sidebar and date drill-down included, came
straight from the models with no hand-written admin code.*

## Quick start

```sh
pip install django-admin-generator
```

Add `django_admin_generator` to your `INSTALLED_APPS`, then generate an admin
and write it to the app's `admin.py`:

```sh
./manage.py admin_generator <app> --write
```

Reload the Django admin. Your models are fully wired up.

## What gets generated

For every model, the generator inspects the fields and picks sensible options:

| Model trait | Generated option |
| --- | --- |
| All local fields | `list_display` |
| `DateField`, `BooleanField`, low-cardinality fields & foreign keys | `list_filter` |
| Foreign key to a large table (≥ `raw_id_threshold`, default 100) | `raw_id_fields` |
| `ManyToManyField` | `autocomplete_fields` (or `raw_id_fields`) |
| `name` / `slug` fields | `search_fields` |
| `slug` field | `prepopulated_fields` (from `name`/`title`) |
| `created_at` / `updated_at` / `joined_at` | `date_hierarchy` |
| `TextField` / `JSONField` / `BinaryField` / `FileField` | shown, but kept out of `list_filter` (DISTINCT is unsafe on some databases) |

The result is plain, readable code you can keep or tweak:

```python
class PostAdmin(ModelAdminBase):
    list_display = (
        'id', 'title', 'slug', 'body', 'created_at',
        'published_at', 'is_published', 'author', 'category',
    )
    list_filter = ('created_at', 'published_at', 'is_published', 'author', 'category')
    autocomplete_fields = ('tags',)
    search_fields = ('slug',)
    prepopulated_fields = {'slug': ['title']}
    date_hierarchy = 'created_at'
```

That produces a fully wired add/change form: prepopulated slugs,
autocomplete for relations, and the right widgets everywhere:

![Auto-generated add form](https://raw.githubusercontent.com/WoLpH/django-admin-generator/develop/docs/images/add-form.png)

## Usage

By default the output is printed to stdout so you can review it before writing:

```sh
./manage.py admin_generator <app>                 # print to stdout
./manage.py admin_generator <app> '^user'         # only models matching a regex
./manage.py admin_generator <app> --write         # write <app>/admin.py
./manage.py admin_generator <app> -o admin.py -f  # custom output file, overwrite
./manage.py admin_generator all                   # every local (non site-packages) app
```

Handy options:

| Option | Effect |
| --- | --- |
| `-w`, `--write` | write to the app's `admin.py` (otherwise stdout) |
| `-o/--output`, `-f/--force`, `-a/--append` | output-file handling |
| `-l/--list-filter-threshold`, `-r/--raw-id-threshold`, `--date-hierarchy-threshold` | tune the heuristics |
| `-s/--search-field`, `-d/--date-hierarchy`, `-p/--prepopulated-fields` | add extra field names |
| `-n/--no-query-db` | don't query the database for row counts |
| `--enable-reversion`, `--disable-json-widget`, `--disable-auto-complete` | integrations & toggles |

Run `./manage.py admin_generator --help` for the full list.

> **Tip:** pairs perfectly with Django's `inspectdb` for
> [legacy databases](https://docs.djangoproject.com/en/stable/howto/legacy-databases/):
> generate the models, then generate the admin.

## Live demo

Spin up a self-documenting blog demo whose `admin.py` is fully auto-generated:

```sh
tox -e demo        # or: uv run --extra demo python test_project/manage.py demo
```

It migrates, seeds realistic data, and opens the admin (login `admin` /
`admin`). The index page explains exactly what was generated and why:

![Self-documenting demo index](https://raw.githubusercontent.com/WoLpH/django-admin-generator/develop/docs/images/admin-index.png)

See [`test_project/README.md`](https://github.com/WoLpH/django-admin-generator/blob/develop/test_project/README.md)
for a guided tour.

## Compatibility

- **Python** 3.10 to 3.14
- **Django** 4.2, 5.0, 5.1, 5.2, 6.0, 6.1

## Development

This project uses [uv](https://docs.astral.sh/uv/) and [tox](https://tox.wiki/):

```sh
uv sync --extra dev      # create the environment
uv run pytest            # run the tests (100% coverage)
uv run ruff check .      # lint
uv run tox               # full matrix: tests, lint, types, docs
```

## Links

- **Documentation**: <https://django-admin-generator.readthedocs.io/en/latest/>
- **Source**: <https://github.com/WoLpH/django-admin-generator>
- **Bug reports**: <https://github.com/WoLpH/django-admin-generator/issues>
- **PyPI**: <https://pypi.org/project/django-admin-generator/>
- **Blog**: <https://w.wol.ph/>

## Support

django-admin-generator is maintained by [Rick van Hattem](https://github.com/wolph) in his own time.

If it saved you an afternoon, a tip covers an hour of issue triage:
[Ko-fi](https://ko-fi.com/wolph_gh) or [GitHub Sponsors](https://github.com/sponsors/wolph).

If your company funds its dependencies, this package is on
[thanks.dev](https://thanks.dev/u/gh/wolph).

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/wolph_gh)

## License

BSD-3-Clause, see [LICENSE](LICENSE).
