Skip to main content

Django Auto Admin Fieldsets

A Django utility for automatically handling unspecified fields in ModelAdmin fieldsets.

Installation

pip install django-auto-admin-fieldsets

Features

  • Automatically add unspecified model fields to a designated placeholder in Django admin fieldsets
  • Works with all field types, including many-to-many fields
  • Respects exclude and readonly_fields settings
  • Supports custom placeholders
  • Provides both a mixin and a standalone function for maximum flexibility

Usage

Using the Mixin

from django.contrib import admin
from django_auto_admin_fieldsets.admin import AutoFieldsetsMixin
from . import models

@admin.register(models.MyModel)
class MyModelAdmin(AutoFieldsetsMixin, admin.ModelAdmin):
    # Define fieldsets as usual with a placeholder
    fieldsets = [
        ("Basic Information", {"fields": ["title", "slug"]}),
        ("Content", {"fields": ["__remaining__"]}),  # All other fields will appear here
    ]

    # Optional: customize the placeholder (default is "__remaining__")
    remaining_fields_placeholder = "__remaining__"

Using the Convenience ModelAdmin

from django.contrib import admin
from django_auto_admin_fieldsets.admin import AutoFieldsetsModelAdmin
from . import models

@admin.register(models.MyModel)
class MyModelAdmin(AutoFieldsetsModelAdmin):
    # Define fieldsets as usual with a placeholder
    fieldsets = [
        ("Basic Information", {"fields": ["title", "slug"]}),
        ("Content", {"fields": ["__remaining__"]}),  # All other fields will appear here
    ]

Using the Standalone Function

from django.contrib import admin
from django_auto_admin_fieldsets.admin import auto_add_fields_to_fieldsets
from . import models

@admin.register(models.MyModel)
class MyModelAdmin(admin.ModelAdmin):
    fieldsets = [
        ("Basic Information", {"fields": ["title", "slug"]}),
        ("Content", {"fields": ["__remaining__"]}),
    ]

    def get_fieldsets(self, request, obj=None):
        fieldsets = super().get_fieldsets(request, obj)
        return auto_add_fields_to_fieldsets(
            model=self.model,
            fieldsets=fieldsets,
            exclude=self.exclude or [],
            placeholder="__remaining__",
        )

admin.site.register(MyModel, MyModelAdmin)

Removing fields from fieldsets

from django_auto_admin_fieldsets.admin import remove_fields_from_fieldsets

fieldsets = [
    ("Basic Information", {"fields": ["title", "slug", "hide_title"]}),
    ("Content", {"fields": ["description", "noindex"]}),
]

fieldsets = remove_fields_from_fieldsets(fieldsets, "hide_title")
fieldsets = remove_fields_from_fieldsets(fieldsets, ["noindex"])

Configuration Options

  • remaining_fields_placeholder: The placeholder string to look for in your fieldsets (default: "__remaining__")

The function also respects the standard Django admin configuration options. If you do not want a field to appear in the resulting fieldsets, add it to the standard exclude list.

Development

Running Tests

Tests should be run using tox, which tests against multiple Python and Django versions:

tox

This will run the test suite against all supported Python and Django combinations as defined in tox.ini.

Code Quality

This project uses pre-commit for code quality checks. After cloning the repository, install the pre-commit hooks:

pre-commit install

The pre-commit configuration includes ruff for linting and formatting. Configuration can be found in pyproject.toml.

Compatibility

  • Python: 3.10 and above
  • Django: 4.2, 5.1, and 5.2 (also tested with Django main)

License

MIT

Release files for django-auto-admin-fieldsets 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-auto-admin-fieldsets 0.3.0
File Size Uploaded
django_auto_admin_fieldsets-0.3.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-auto-admin-fieldsets 0.3.0
File Interpreter ABI Platform
django_auto_admin_fieldsets-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / django_auto_admin_fieldsets-0.3.0.tar.gz

Download URL django_auto_admin_fieldsets-0.3.0.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
db916626edd233de1eeda876d6aab6f93eac6d0a1c34f87491d3d03543802ca2
BLAKE2b-256 checksum
How to use checksums
e2b8ccff57e030e2b6684b37b51d52401a330008115c7dd8d17fb3303f851807
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / django_auto_admin_fieldsets-0.3.0-py3-none-any.whl

Download URL django_auto_admin_fieldsets-0.3.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e24f4757d6bd056c2392b044ab0cdb21d813f69e33caa981dda26ffe703db91
BLAKE2b-256 checksum
How to use checksums
9d1bf6bb7972b7580495d3f01e9a45ee021683eea22a787c33873a056462f9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page