Automatic admin registration for Django projects.
Project description
Django Admin Magic
A simple Django app to automatically register your models with the admin site.
What?
It auto-generates all your admin pages programatically! It's awesome!
Why?
Sometimes you're working on a django app and you just wanna see the models, and you don't want to define a brand new admin instance every time, and you just want things to work and look at your data in the admin view. If so, this package is for you!
Tested Dependencies
This package is thoroughly tested against the following dependency combinations:
| Django Version | Python 3.10 | Python 3.11 | Python 3.12 |
|---|---|---|---|
| 3.2 | ✅ | ✅ | ✅ |
| 4.0 | ✅ | ✅ | ✅ |
| 4.1 | ✅ | ✅ | ✅ |
| 4.2 | ✅ | ✅ | ✅ |
| 5.0 | ✅ | ✅ | ✅ |
Note: This package requires Python 3.10+ due to its use of modern type hint syntax (union types with | operator). While Python 3.8 and 3.9 could be supported by using typing.Union and typing.Optional, we prefer the cleaner, more readable modern syntax introduced in Python 3.10.
Continuous Integration
The test matrix includes:
- 5 Django versions (3.2, 4.0, 4.1, 4.2, 5.0)
- 3 Python versions (3.10, 3.11, 3.12)
- Code coverage reporting
- Linting with ruff
- Security scanning with bandit
Installation
Install the package from PyPI:
pip install django-admin-magic
Then, add it to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
# ...
"django_admin_magic",
# ...
]
Demo
A full-featured demo app is included in this repository to showcase all features of Django Admin Magic, including:
- Automatic admin registration for a variety of model types
- Sample data for all models
- Auto-generated superuser for instant login
- Landing page listing all registered models
Quickstart:
python demo_app/setup_demo.py
python demo_app/manage.py runserver
- Main demo: http://127.0.0.1:8000/
- Admin: http://127.0.0.1:8000/admin/ (login:
admin/admin123)
See demo_app/README.md for full demo instructions, troubleshooting, and customization tips.
Configuration
Django Auto Admin supports multiple ways to specify which apps to register models for:
Method 1: Single App Label (Traditional)
Specify a single app_label in your settings.py:
AUTO_ADMIN_APP_LABEL = "my_app"
Method 2: Multiple App Labels
Specify multiple app labels as a list:
# Option A: Using APP_LABELS setting
AUTO_ADMIN_APP_LABELS = ["my_app", "another_app", "third_app"]
# Option B: Using APP_LABEL as a list
AUTO_ADMIN_APP_LABEL = ["my_app", "another_app", "third_app"]
Method 3: Auto-Discover All Apps
Automatically discover and register all installed apps that have models:
AUTO_ADMIN_AUTO_DISCOVER_ALL_APPS = True
Method 4: Manual Registration in admin.py
If no configuration is provided in settings, you can manually create registrars in your admin.py files:
# In your app's admin.py file
from django_admin_magic.utils import create_auto_admin_registrar
# Auto-determine app label from current package
registrar = create_auto_admin_registrar()
# Or specify a specific app label
registrar = create_auto_admin_registrar("my_app")
# Or register multiple apps
from django_admin_magic.utils import create_auto_admin_registrar_for_apps
registrar = create_auto_admin_registrar_for_apps(["my_app", "another_app"])
# Or register all discovered apps
from django_admin_magic.utils import create_auto_admin_registrar_for_all_apps
registrar = create_auto_admin_registrar_for_all_apps()
Configuration Priority
The library follows this priority order for determining which apps to register:
- Explicitly provided parameters in admin.py files
- Settings configuration (
AUTO_ADMIN_APP_LABEL,AUTO_ADMIN_APP_LABELS,AUTO_ADMIN_AUTO_DISCOVER_ALL_APPS) - Auto-discovery if enabled
- No registration if nothing is configured
Advanced Configuration
You can override the default settings by adding them to your settings.py with the AUTO_ADMIN_ prefix.
DEFAULT_EXCLUDED_TERMS: A list of strings to exclude from thelist_displaywhen it's auto-generated.DEFAULT_DO_NOT_REGISTER_FILTER_STRING_LIST: A list of strings. Any model whose name contains one of these strings will not be registered.ADMIN_TUPLE_ATTRIBUTES_TO_LIST: A list of admin attributes that are typically tuples but need to be lists for modification (e.g.,list_display,list_filter).REORDER_LINKIFY_FIELDS: Boolean flag (default:True) that controls whether linkify fields should be reordered to avoid being the first column in admin changelist views. This prevents issues with clicking on the first column, which is often used for row selection checkboxes.
Linkify Field Reordering
By default, Django Auto Admin automatically reorders list_display fields to ensure that linkify functions (foreign key links) are not the first column in admin changelist views. This is because the first column in Django admin is often used for row selection checkboxes, and having a clickable link there can interfere with the selection functionality.
Example:
# Without reordering (problematic):
list_display = [linkify('parent'), 'name', 'created_at']
# With reordering (fixed):
list_display = ['name', linkify('parent'), 'created_at']
You can disable this behavior by setting:
AUTO_ADMIN_REORDER_LINKIFY_FIELDS = False
Usage
Once installed and configured, the library will automatically register all the models in the specified app(s) with the admin site.
Customizing the Admin
You can still customize the admin classes after they've been registered. The AdminModelRegistrar instance provides several methods for this purpose. You can get the registrar instance from the apps registry.
from django.apps import apps
# Get the registrar instance
registrar = apps.get_app_config("django_admin_magic").registrar
# Get the admin class for a model
MyModelAdmin = registrar.return_admin_class_for_model(MyModel)
# Customize the admin class
MyModelAdmin.list_display.append("my_custom_field")
Available Methods
append_list_display(model, list_display)prepend_list_display(model, list_display)remove_list_display(model, list_display_to_remove)append_filter_display(model, list_filter)add_search_fields(model, search_fields)update_list_select_related(model, list_select_related)add_admin_method(model, method_name, method_func, short_description=None, is_action=False)append_inline(model, inline_class)
Polymorphic Models
This library automatically detects if django-polymorphic is installed and will use the appropriate admin classes for polymorphic models. There is no extra configuration required.
Development
CI/CD Pipeline
This project uses GitHub Actions for continuous integration and deployment:
- Tests: Runs across Django 3.2-5.0 and Python 3.8-3.12
- Linting: Code quality checks with ruff
- Security: Automated security scanning with bandit
- Deployment: Automatic PyPI deployment on releases
- Badges: Real-time status badges updated automatically
For setup instructions, see SETUP_CI_CD.md.
Local Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
ruff check .
ruff format .
# Test CI locally
python scripts/test-ci-locally.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_admin_magic-0.1.5.tar.gz.
File metadata
- Download URL: django_admin_magic-0.1.5.tar.gz
- Upload date:
- Size: 185.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bca203915717204ffc983809a0f5f63d6c31ead46e448cb4da04138d1af4a7f2
|
|
| MD5 |
6cd7a434bc4e8bf7175876a2f956b805
|
|
| BLAKE2b-256 |
c6c8685ef1635a2922635693e011427a2397ab658a00f78256d81f2047d01ab8
|
Provenance
The following attestation bundles were made for django_admin_magic-0.1.5.tar.gz:
Publisher:
publish.yml on billthefighter/django-admin-magic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_magic-0.1.5.tar.gz -
Subject digest:
bca203915717204ffc983809a0f5f63d6c31ead46e448cb4da04138d1af4a7f2 - Sigstore transparency entry: 411734965
- Sigstore integration time:
-
Permalink:
billthefighter/django-admin-magic@42d19597d33b48134eb89bdc6c0e279bcf6bdd57 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/billthefighter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@42d19597d33b48134eb89bdc6c0e279bcf6bdd57 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_admin_magic-0.1.5-py3-none-any.whl.
File metadata
- Download URL: django_admin_magic-0.1.5-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da86a6b700b4a96cc742f308f24ab753ac409e429cb444564992400ec529c83a
|
|
| MD5 |
6ac6888deb2e1d58bfad37643c07cae4
|
|
| BLAKE2b-256 |
01578b8eb87946823e79545d32e302517e2d0c5fa3c487551c547c0758f46eca
|
Provenance
The following attestation bundles were made for django_admin_magic-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on billthefighter/django-admin-magic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_magic-0.1.5-py3-none-any.whl -
Subject digest:
da86a6b700b4a96cc742f308f24ab753ac409e429cb444564992400ec529c83a - Sigstore transparency entry: 411734977
- Sigstore integration time:
-
Permalink:
billthefighter/django-admin-magic@42d19597d33b48134eb89bdc6c0e279bcf6bdd57 -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/billthefighter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@42d19597d33b48134eb89bdc6c0e279bcf6bdd57 -
Trigger Event:
push
-
Statement type: