Skip to main content

A Django utility for automatically handling unspecified fields in admin fieldsets

Project description

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 .models import MyModel

class MyModelAdmin(AutoFieldsetsMixin, admin.ModelAdmin):
    model = MyModel

    # 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__"

admin.site.register(MyModel, MyModelAdmin)

Using the Convenience ModelAdmin

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

class MyModelAdmin(AutoFieldsetsModelAdmin):
    model = MyModel

    # Define fieldsets as usual with a placeholder
    fieldsets = [
        ("Basic Information", {"fields": ["title", "slug"]}),
        ("Content", {"fields": ["__remaining__"]}),  # All other fields will appear here
    ]

admin.site.register(MyModel, MyModelAdmin)

Using the Standalone Function

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

class MyModelAdmin(admin.ModelAdmin):
    model = MyModel

    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 [],
            readonly_fields=self.get_readonly_fields(request, obj),
            placeholder="__remaining__",
        )

admin.site.register(MyModel, MyModelAdmin)

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:
    • exclude: Fields that should not be displayed in the admin
    • readonly_fields: Fields that should be displayed as read-only

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

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

django_auto_admin_fieldsets-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_auto_admin_fieldsets-0.1.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file django_auto_admin_fieldsets-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django_auto_admin_fieldsets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 38f40aa94f85d8d1281ee7eb108525a2554c9657cbbc0ee87748d4bab883cbad
MD5 05ce688f7709f5ac6a708ea6f8dbe98d
BLAKE2b-256 c6a60b4017ff3838cf10543dd755cba0f46f6cdce19dc9a8c14c8a2e9170f49f

See more details on using hashes here.

File details

Details for the file django_auto_admin_fieldsets-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_auto_admin_fieldsets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32dc80509ff951c213aa353167175d3e276a7a8a5f2867d8b25df68c17cb1300
MD5 744632df07c7caf281810bba44ed40e2
BLAKE2b-256 72b612157d350bd7a5ad0f38dd110d683df22b39a642c61fc62c594418fa0b28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page